为了账号安全,请及时绑定邮箱和手机立即绑定

python中为什么方法在类中定义的,但是内存地址却不同??

python中为什么方法在类中定义的,但是内存地址却不同??

慕丝7291255 2018-08-09 11:10:38
>>> class Student(): def __init__(self,name,score):self.name=nameself.score=scoredef print_score(self):print ('%s:%s'%(self.name,self.score))>>> bart=Student('王大治',23)>>> id(Student)54456368  //这里是类的内存地址>>> id(bart)5319568  //这个是实例内存地址>>> id(bart.print_score)4298912 //这个是方法的内存地址。这个方法,和实例。类的内存地址都不同,为什么呢?>>> id(bart.score)503371152 >>> k=23>>> id(k)503371152 从上述看,变量,实例,方法 ,类,的内存地址都不同,如果在内存中,那是怎么去连接运行的呢?
查看完整描述

1 回答

?
慕沐林林

TA贡献2016条经验 获得超9个赞

虽然不懂什么叫 Python的内存问题,下面是help(id)的结果:

>>> help(id)
Help on built-in function id in module builtins:

id(obj, /)
Return the identity of an object.

This is guaranteed to be unique among simultaneously existing objects.

---

获取的identity就是唯一的。

类也是个内存中的对象,类对象,Python中一切皆对象。

 

“连接运行”,WHY?


查看完整回答
反对 回复 2018-09-03
  • 1 回答
  • 0 关注
  • 987 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信