在 Python 中,几乎所有的东西都是对象。
整数是对象:
In [1]:
a = 257In [2]:
type(a)Out[2]:
intIn [3]:
id(a)Out[3]:
53187032Lb 和 a 是同一个对象:
In [4]:
b = aIn [5]:
id(b)Out[5]:
53187032LIn [6]:
c = 258
id(c)Out[6]:
53186960L函数:
In [7]:
def foo():
print 'hi'In [8]:
type(foo)Out[8]:
functionIn [9]:
id(foo)Out[9]:
63632664Ltype 函数本身也是对象:
In [10]:
type(type)Out[10]:
typeIn [11]:
id(type)Out[11]:
506070640L只有一些保留的关键词不是对象:
In [12]:
id(if) File "<ipython-input-12-1e0d1307109a>", line 1
id(if)
^
SyntaxError: invalid syntaxIn [13]:
id(+) File "<ipython-input-13-86853fe3c6fd>", line 1
id(+)
^
SyntaxError: invalid syntax