Python 内建函数 - classmethod(function)

Python 的 classmethod 内建函数用于创建类方法,它接收类作为第一个参数而不是实例。类方法可以通过类或实例调用,并在派生类调用时接收派生类对象。区别于 C++ 或 Java 的静态方法,Python 还提供了 staticmethod 用于类似功能。类方法的详细信息可以在 Python 的标准类型层次结构文档中找到。
摘要由CSDN通过智能技术生成

Manual

Return a class method for function.

A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:

class C:
    @classmethod
    def f(cls, arg1, arg2, ...): ...

The @classmethod form is a function decorator – see the description of function definitions in Function definitions for details.

It can be called either on the class (such as C.f()) or on an instance (such as C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值