计算长度
In [140]: a='hello'
In [141]: len(a)
Out[141]: 5
取极值
In [142]: max('1234')
Out[142]: '4'
In [143]: min('1234')
Out[143]: '1'
枚举
可以同时遍历索引和遍历元素
In [151]: str='hello'
In [152]: for i,j in enumerate(str):
.....: print i,j
.....:
0 h
1 e
2 l
3 l
4 o
比较
cmp()
In [37]: cmp(1,2)
Out[37]: -1
In [38]: cmp(2,1)
Out[38]: 1
In [39]: cmp(1,1)
Out[39]: 0
查看变量类型
type(变量名)
In [42]: a=1
In [43]: type(a)
Out[43]: int
类型转换
In [35]: a=123
In [36]: type(a)
Out[36]: int
In [37]: a=long(a)
In [38]: type(a)
Out[38]: long
In [40]: str(1)
Out[40]: '1'
zip
In [153]: s1='123'
In [154]: s2='abc'
In [155]: s3='ABC'
In [156]: zip(s1,s2,s3)
Out[156]: [('1', 'a', 'A'), ('2', 'b', 'B'), ('3', 'c', 'C')]