python tutorial 学习笔记(二) Sequence type
2011-04-01 15:58
525 查看
built-in functions:
range()len(object)
keyword in, return boolean
filter(function,sequence)
map(function,*sequence)
reduce(function,sequence)
enumerate(object) –> [(0,item0),(1,item1),…]
zip(seq1,seq2,…) –> [ (seq1[0],seq2[0]), (seq1[1],seq2[1] ), ….. ]
reversed(sequence), the original sequence object is not changed
sorted(sequence), the original sequence object is not changed
Note: sequence can be type str,unicode,list,tuple,buffer,xrange
list: [item1,item2,item3,…]
list.append(x) list.extend(l)list.pop([i]),list.remove(x), del list[int:int]
li_a + li_b
List comporehension: [ expression for elem in sequence if condition]
turple:(item1,item2…)
immutabletuple with one item: (“hello”,
) or “hello”,
packing and unpacking:
t =12345,54321,”hello"!” #returns a turple
x,y,z = t #t can be any sequence type, number of left-side variables must equal len(t)
set, an unordered collection of unique elements
set() function, return set typea-b, a|b, a&b, a^b
dictionary: {key1:val1, key2:val2, …}
.keys()
.sort()
built-in function dict( [(key1,value1), (key2,value2), ….] ) constructs a dictionary object
dict( key1=val1, key2=val2, …. ) , its keyword arguments form
Looping Techniques:
for k,v in dictionary.iteritems(): print k,vfor i,v in enumerate( list ): print i,v
for q,a in zip(list1,list2): print q,a
Comparing:
Sequence objects may be compared to other objects with the same sequence type. The comparison uses lexicographicalordering: first the first two items are compared, and if they differ this determines the outcome of the comparison; if they are equal, the next two items are compared, and so on, until either sequence is exhausted
相关文章推荐
- Python Tutorial 学习笔记2
- Python学习网站(简明python教程,The Python Tutorial,Python学习笔记,啄木鸟社区)
- Python tutorial: python中文快速学习笔记 - 数字与字符串
- python tutorial 学习笔记(三)
- python tutorial 学习笔记(四) Input and Output, 字符串的转换等
- python tutorial 学习笔记(一)
- Python Tutorial 学习笔记5 --IO
- Python Tutorial 学习笔记6 --Errors and Exceptions
- python tutorial 学习笔记 (五) scope,namespace
- Python Tutorial 学习笔记1
- Python Tutorial 学习笔记3 -- Python Data Structures
- Python Tutorial 学习笔记4 ——Module
- python tutorial 学习笔记(七)Errors and Exceptions
- Python学习笔记之逻辑回归
- python学习笔记-网络刷博器
- 【Python】学习笔记——-6.1、使用模块
- Python 学习笔记 - 4.if 表达式
- python学习笔记——高阶函数map()
- Python学习笔记(十七)ndarray
- Python学习笔记——函数式编程