Python Basic

来源:互联网 发布:网站注册域名 编辑:程序博客网 时间:2024/05/17 09:22

 

1. swap two elements
    a, b = b, a  #fk, it is so easy.

2. Chained Logical
   
a < b <= c <d
    same with:
    a< b and b<=c and c<d
    #lol, I love python, easy easy and easy

3. Indexing a sequence
 
   x  = [1,2,3,4]
    x [1] #2
    x[2:] #2,3,4
    x[-1] #4
    del x[1] #x = [2,3,4]

 

4. Iterators using "for"
   
for x in c:
        statement(s)

5. List comprehensions
   

   1: a = [1,2,3,4,5]
   2: result1 = [x for x in a]
   3: print result1
   4: #print out [1,2,3,4,5]
   5: #This is equals to 
   6: result1 = []
   7: for x in a:
   8:     result1.append(x)

6. Parameters (* & **)
    *identifier  indicates that any call to the function may supply extra positional arguments
    **identifier indicates that any call to the function may supply extra named agruments.
   

 

原创粉丝点击