在Python中,我可以使用 @classmethod装饰器: >>> class C: ... @classmethod ... def f(cls): ... print(f'f called with cls={cls}') ... >>> C.f() f called with cls=<class '__main__.C'> 另外,我可以在元类上使用常规(实例)方法: >>> class M(type): ... def f(cls): ... print(f'f called with cls={cls}') ... >>> class C(metaclass=M): ... pass ... >>> C.f() f called with cls=<class '__main__.C'> 如输出所示 …