zoukankan      html  css  js  c++  java
  • python Basic usage

    __author__ = 'student'
    l=[]
    l=list('yaoxiaohua')
    print l
    print l[0:2]
    l=list('abc')
    print l*3
    l.append(4)
    print l
    l.extend('de')
    print l
    print l.count('a')
    l.sort()
    print l
    l.reverse()
    print l
    l[0:2]=[1,2,3]
    print l
    print list(map (ord,'spam'))
    l = ['abc', 'ABD', 'aBe']
    l.sort(key=str.lower) # sort in place not return new object, be ware of this
    print l
    print sorted(l, key=str.upper, reverse=True) #return new object not change l
    print l
    
    '''
    while True:
        reply=raw_input("please input what you want to say:")
        if reply=='exit':
            break
        else:
            print reply.upper()
    '''
    print 100**2
    a,b='A','B'
    print a
    print a,b
    
    L = [1, 2]
    M = L  # L and M reference the same object
    L = L + [3, 4]  # Concatenation makes a new object
    print L, M  # Changes L but not M
    L = [1, 2]
    M = L
    L += [3, 4]  # But += really means extend
    print L, M  # M sees the in-place change too!
    
    L = L.append(4)  # But append returns None, not L
    print(L)  # So we lose our list! None
    
    data = (123, 'abc', 3.14)
    for i, value in enumerate(data):
        print i, value
    
    import re
    m=re.match(r'd+','123:abc')
    if m is not None : print m.group()
    
    import random
    for i in range(1,10):
        print random.choice(xrange(10))
    
    l=[1,2]
    sum= lambda a,b:a+b
    print 'sum is :' , sum(*l) # parse the list to function parameters
    d={'a':1,'b':2}
    print 'sum is ', sum(**d) # ** parse the dictionary to function parameters
    
    with open(r'd:	est.txt','w') as file: # with clause the system will release resource automatically
        for x in range(0,26,1):
            file.write(chr(ord('a')+x))
            file.write('
    ')
    with open(r'd:	est.txt','r') as file:
        for line in file:
            print line.rstrip() # rstrip remove the end line in the string
  • 相关阅读:
    图解 PHP运行环境配置和开发环境的配置
    PHP学习笔记(2)语法和数据类型
    Jquery调用 新浪微博API 用户资料
    [转载]并行计算部分总结
    Qt QTreeWidget节点的添加+双击响应+删除详解
    C/C++中函数参数传递详解
    C语言预处理——宏定义
    cuda工程在VS中使用心得
    MPI用于矩阵乘积示例
    开到荼蘼花事了,永世相守孟婆桥
  • 原文地址:https://www.cnblogs.com/huaxiaoyao/p/4493232.html
Copyright © 2011-2022 走看看