Python classmethod 修饰符
描述
Python classmethod 修饰符对应的函数不需要实例化,不需要 self 参数,但第一个参数需要是表示自身类的 cls 参数,可以来调用类的属性,类的方法,实例化对象等。
语法
classmethod 语法:
classmethod
参数
- 无。
返回值
返回函数的类方法。
实例
以下实例展示了 classmethod 的使用方法:
func2
1
foo
输出结果为:
func2
1
foo
以上内容是否对您有帮助:
W3Cschool
恭喜您成为首批注册用户
获得88经验值奖励
Python classmethod 修饰符对应的函数不需要实例化,不需要 self 参数,但第一个参数需要是表示自身类的 cls 参数,可以来调用类的属性,类的方法,实例化对象等。
classmethod 语法:
classmethod
返回函数的类方法。
以下实例展示了 classmethod 的使用方法:
func2
1
foo
输出结果为:
func2
1
foo
Copyright©2021 w3cschool编程狮|闽ICP备15016281号-3|闽公网安备35020302033924号
违法和不良信息举报电话:173-0602-2364|举报邮箱:jubao@eeedong.com
扫描二维码
下载编程狮App
编程狮公众号
联系方式:
更多建议: