【发布时间】:2020-08-18 11:13:33
【问题描述】:
考虑以下类:
class Employee:
def __init__(self,first,last,pay):
self.first=first;self.last=last
self.pay=pay
self.email=first.lower()+'.'+last.lower()+"@company.com"
def fullname(self): return "{} {}".format(self.first, self.last)
如果我像这样访问全名方法:
em1.fullname #assume em1 object already exists
我得到以下输出:
<bound method Employee.fullname of <__main__.Employee object at 0x7ff7883acc88>>`
但是,如果我像这样访问全名方法:
Employee.fullname
我得到以下输出:<function Employee.fullname at 0x7ff7883c9268>
为什么同一个函数/方法有两种不同的定义?我仍在访问内存中相同的方法/函数对象,对吧?
【问题讨论】:
标签: python function class object methods