1 Star 0 Fork 55

zj507071 / AiLearning

forked from OpenDocCN / ailearning 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
103.md 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
布客飞龙 提交于 2020-10-19 21:08 . 2020-10-19 21:08:55

什么是对象?

Python 中,几乎所有的东西都是对象。

整数是对象:

In [1]:

a = 257

In [2]:

type(a)

Out[2]:

int

In [3]:

id(a)

Out[3]:

53187032L

ba 是同一个对象:

In [4]:

b = a

In [5]:

id(b)

Out[5]:

53187032L

In [6]:

c = 258
id(c)

Out[6]:

53186960L

函数:

In [7]:

def foo():
    print 'hi'

In [8]:

type(foo)

Out[8]:

function

In [9]:

id(foo)

Out[9]:

63632664L

type 函数本身也是对象:

In [10]:

type(type)

Out[10]:

type

In [11]:

id(type)

Out[11]:

506070640L

只有一些保留的关键词不是对象:

In [12]:

id(if)
 File "<ipython-input-12-1e0d1307109a>", line 1
 id(if)
 ^
SyntaxError: invalid syntax

In [13]:

id(+)
 File "<ipython-input-13-86853fe3c6fd>", line 1
 id(+)
 ^
SyntaxError: invalid syntax
Python
1
https://gitee.com/zj507071/AiLearning.git
git@gitee.com:zj507071/AiLearning.git
zj507071
AiLearning
AiLearning
master

搜索帮助