首页
注册
登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请
登录
V2EX
›
ilucio
›
全部回复第 3 页 / 共 3 页
回复总数
41
1
2
3
❮
❯
2018-05-04 14:54:08 +08:00
回复了
wellsc
创建的主题
›
Python
›
问个问题,面试官问你 “ Python 的对象方法是怎么存储的”,该怎么回答
感觉问的应该是类的知识。在类里定义一个方法,会在堆上开辟内存生成一个函数对象,并把这个对象名放在类的__dict__中。
class apple(object):
def price (self):
print '2'
def weight (self):
print '400g'
print apple.__dict__
{'__module__': '__main__', 'weight': <function weight at 0x03868DB0>, 'price': <function price at 0x03868D70>, '__dict__': <attribute '__dict__' of 'apple' objects>, '__weakref__': <attribute '__weakref__' of 'apple' objects>, '__doc__': None}
可见方法 price 和 weight 分别在堆上的不同位置。
1
2
3
❮
❯
关于
·
帮助文档
·
自助推广系统
·
博客
·
API
·
FAQ
·
Solana
·
4073 人在线
最高记录 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 10ms ·
UTC 10:11
·
PVG 18:11
·
LAX 02:11
·
JFK 05:11
♥ Do have faith in what you're doing.
❯