【发布时间】:2016-05-12 12:21:19
【问题描述】:
我观察到至少 3 种与 Python 3 中的函数相关的类型:
>>> class A():
... def f(): pass
...
>>> A.f
<function A.f at 0x7fcaef304268>
>>> A().f
<bound method A.f of <__main__.A object at 0x7fcaef2fae80
>>> set.union
<method 'union' of 'set' objects>
我想知道“函数”、“方法”和“绑定方法”有什么区别? 'method' 是 Python 2 中等价于 'unbound method' 的类型吗?
【问题讨论】:
标签: python function python-3.x python-internals