python tutorial 学习笔记(二) Sequence type
来源:互联网 发布:linux设置ftp用户目录 编辑:程序博客网 时间:2024/06/05 15:01
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…)
immutable
tuple 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 type
a-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,v
for 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 lexicographical ordering: 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 学习笔记(二) Sequence type
- python tutorial 学习笔记(一)
- python tutorial 学习笔记(三)
- python tutorial 学习笔记(六)class
- Python Tutorial 学习笔记1
- Python Tutorial 学习笔记2
- 《Beginning Python From Novice to Professional》学习笔记二:Sequence
- python学习笔记-(3)序列-Sequence
- An ffmpeg and SDL Tutorial 学习笔记(二)
- python tutorial 学习笔记(七)Errors and Exceptions
- Python学习网站(简明python教程,The Python Tutorial,Python学习笔记,啄木鸟社区)
- ffmpeg的tutorial中文版学习笔记(二)
- Unity学习笔记二 - Survival Shooter Tutorial
- ffmpeg的tutorial中文版学习笔记(二)
- python tutorial 学习笔记 (五) scope,namespace
- Python Tutorial 学习笔记5 --IO
- UML Distilled 3rd 学习笔记(二) - Sequence Diagrams
- python学习笔记(二)
- vb.net中用户自定义控件中属性、方法、事件的理解
- java异常处理之自定义异常类(转)
- FCKeditor隐藏工具栏
- 数据库中NCHAR 、CHAR等的区别
- Android articles 翻译之一:Avoiding Memory Leaks
- python tutorial 学习笔记(二) Sequence type
- (JavaCard)JavaCard222VM Spec(JavaCard 2.2.2 虚拟机规范-中英文对照,第五章)
- windows 7 下安装 Android 设备驱动
- mysql数据库中不能插入中文
- MVC 小练
- socket网络通信(tcp)
- 软件需求管理工具列表大全
- 间接成员操作符-> 和直接成员操作符的区别.
- 使用Razor引擎做一个SEO Helper