Python staticmethod() 函数
2021/11/1 22:40:01
本文主要是介绍Python staticmethod() 函数,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Python staticmethod() 函数
Python 内置函数
python staticmethod 返回函数的静态方法。
该方法不强制要求传递参数,如下声明一个静态方法:
class C(object): @staticmethod def f(arg1, arg2, ...): ...
以上实例声明了静态方法 f,从而可以实现实例化使用 C().f(),当然也可以不实例化调用该方法 C.f()。
函数语法
staticmethod(function)
参数说明:
- 无
实例
#!/usr/bin/python # -*- coding: UTF-8 -*- class C(object): @staticmethod def f(): print('runoob'); C.f(); # 静态方法无需实例化 cobj = C() cobj.f() # 也可以实例化后调用以上实例输出结果为:
runoob runoob
Python 内置函数
Python OS 文件/目录方法 Python 面向对象1 篇笔记 写笔记
这篇关于Python staticmethod() 函数的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-18初探Python股票自动化交易:入门指南
- 2024-09-18Python量化入门:轻松掌握量化分析基础与实战
- 2024-09-18Python量化交易:入门指南与实践
- 2024-09-18Python量化交易:入门指南与实战技巧
- 2024-09-14Python人工智能项目实战:从零开始的实践指南
- 2024-09-14探索Python人工智能资料:初学者的指南
- 2024-09-14Python人工智能资料:初学者的全面指南
- 2024-09-13Matplotlib入门:轻松绘制Python数据可视化图表
- 2024-09-13Python人工智能:初学者的入门指南
- 2024-09-13Python人工智能:轻松入门与实践
Naive!
ann***ous@anno.moe
132staticmethod 参数要求是 Callable, 也就是说 Class 也是可以的:
Naive!Naive!
ann***ous@anno.moe
2年前 (2019-10-29)