内建函数
max()
min()
pow()
divmod()
callable()
In [23]: def a():
…: pass
…: callable(a)
…:
Out[23]: True
type()
isnstance()
In [28]: isinstance(l,list)
Out[28]: True
In [29]: isinstance(l,str)
Out[29]: False
In [30]: isinstance(s,str)
Out[30]: True
In [31]: isinstance(s,int)
Out[31]: False
In [32]: isinstance(s,(int,str))
Out[32]: True
In [33]: isinstance(s,(int,dict))
Out[33]: False
In [35]: class A(object):
…: pass
…: a
…: a=A()
…:
In [36]: isinstance(a,A)
Out[36]: True
cmp()
In [38]: cmp(1,1)
Out[38]: 0
In [39]: cmp(0,1)
Out[39]: -1
In [40]: cmp(2,1)
Out[40]: 1
In [41]: cmp(‘hello’,‘hello’)
Out[41]: 0
In [42]: cmp(‘helloa’,‘hello’)
Out[42]: 1
In [43]: cmp(‘zlloa’,‘hello’)
Out[43]: 1
In [44]: cmp(‘z’,‘hello’)
Out[44]: 1
In [45]: cmp(‘helloa’,‘hello’)
Out[45]: 1
range()
In [46]: range(10)
Out[46]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
In [47]: xrange(10)
Out[47]: xrange(10)
In [48]: a=range(10)
In [49]: a
Out[49]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
xrange()
int ()
In [50]: int(12.2)
Out[50]: 12
complex()
In [52]: complex(‘12’)
Out[52]: (12+0j)
eval
In [5]: type(eval(hex(10)))
Out[5]: int
In [6]: eval("[‘a’,‘b’,1]")
Out[6]: [‘a’, ‘b’, 1]
In [7]: chr(1)
Out[7]: ‘\x01’
In [8]: chr(100)
Out[8]: ‘d’
In [9]: chr(97)
Out[9]: ‘a’
In [10]: chr(65)
Out[10]: ‘A’
In [11]: help(ord)
In [14]: ord(‘A’)
Out[14]: 65
In [15]: s=‘hello’
In [16]: s.capitalize()
Out[16]: 'Hello
In [57]: string.lowercase
Out[57]: ‘abcdefghijklmnopqrstuvwxyz’
In [58]: string.uppercase
Out[58]: ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’
In [59]: string.capitalize
Out[59]:
In [60]: string.capitalize(‘hello’)
Out[60]: ‘Hello’
In [80]: def f(x,y):
…: return x+y
…: reduce (f,range(1,101))
…:
Out[80]: 5050