Home
Sign Up
Sign In
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member
Sign In
V2EX
›
ilucio
›
全部回复第 3 页 / 共 3 页
回复总数
41
1
2
3
❮
❯
2018 年 5 月 4 日
回复了
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
❮
❯
About
·
Help
·
Advertise
·
Blog
·
API
·
FAQ
·
Solana
·
5664 Online
Highest 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 14ms ·
UTC 06:27
·
PVG 14:27
·
LAX 23:27
·
JFK 02:27
♥ Do have faith in what you're doing.
❯