Built-in Functions | ||||
---|---|---|---|---|
abs() | divmod() | input() | open() | staticmethod() |
all() | enumerate() | int() | ord() | str() |
any() | eval() | isinstance() | pow() | sum() |
basestring() | execfile() | issubclass() | print() | super() |
bin() | file() | iter() | property() | tuple() |
bool() | filter() | len() | range() | type() |
bytearray() | float() | list() | raw_input() | unichr() |
callable() | format() | locals() | reduce() | unicode() |
chr() | frozenset() | long() | reload() | vars() |
classmethod() | getattr() | map() | repr() | xrange() |
cmp() | globals() | max() | reversed() | zip() |
compile() | hasattr() | memoryview() | round() | __import__() |
complex() | hash() | min() | set() | apply() |
delattr() | help() | next() | setattr() | buffer() |
dict() | hex() | object() | slice() | coerce() |
dir() | id() | oct() | sorted() | intern() |
示例:bin(127)
结果:'0b1111111'
|
示例:bool(1)
结果:True
|
示例1:bytearray('abcdef', 'utf_8')
结果:bytearray(b'abcdef')
示例2:bytearray([96, 97, 98, 99])
结果:bytearray(b'`abc')
|
示例:chr(99)
结果:'c'
|
示例:cmp('a',chr(97))
结果:0
|
>>> x = 1
>>> print eval('x+1')
2
|
>>> float('1.01')
1.01
>>> float(1)
1.0
|
>>> 'i' in globals()
True
|
>>> hash(1) == hash(1.0)
True
|
>>> hex(96)
'0x60'
|
>>> a = 'hello'
>>> isinstance(a, str)
True
|
>>> a = [1,2,3,4,5]
>>> len(a)
5
|
>>> list('abcdefg')
['a', 'b', 'c', 'd', 'e', 'f', 'g']
|
>>> max([100,200,102,103,80])
200
|
>>> oct(0x80)
'0200'
|
f = open('c:\\test.txt', 'wb') |
>>> ord('r')
114
|
>>> print('Hello world!')
Hello world!
|
>>> a = 0
>>> for i in range(0,101):
a = a + i
>>> print a
5050
|
>>> x = raw_input('Input 1 number: ')
Input 1 number:
5
>>> print x
5
|
import os
reload(os)
|
>>> x = [1,2,3,4,5]
>>> y = repr(x)
>>> type(y)
<type 'str'>
>>> print y
[1, 2, 3, 4, 5]
|
>>> x = [1,2,3,4,'5']
>>> print(str(x))
[1, 2, 3, 4, '5']
|
>>> x = range(0,101)
>>> sum(x)
5050
|
>>> tuple('abcdef')
('a', 'b', 'c', 'd', 'e', 'f')
|
>>> x = tuple('abcdef')
>>> type(x)
<type 'tuple'>
|
>>> unichr(97)
u'a'
|
>>> range(0,5,1)
[0, 1, 2, 3, 4]
>>> xrange(0,5,1)
xrange(5)
|