【发布时间】:2011-06-04 12:31:48
【问题描述】:
为什么有时在 Python 类中使用 cls 而不是 self 作为参数?
例如:
class Person:
def __init__(self, firstname, lastname):
self.firstname = firstname
self.lastname = lastname
@classmethod
def from_fullname(cls, fullname):
cls.firstname, cls.lastname = fullname.split(' ', 1)
【问题讨论】:
标签: python class object terminology self