Python内置函数 - staticmethod() 函数
  
- UID
- 2
- 积分
- 2914403
- 威望
- 1407234 布
- 龙e币
- 1507169 刀
- 在线时间
- 13521 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2025-3-3

|
Python内置函数 - staticmethod() 函数
python staticmethod 返回函数的静态方法。
该方法不强制要求传递参数,如下声明一个静态方法:- class C(object):
- @staticmethod
- def f(arg1, arg2, ...):
- ...
复制代码 以上实例声明了静态方法 f,从而可以实现实例化使用 C().f(),当然也可以不实例化调用该方法 C.f()。
函数语法参数说明:
无
实例- #!/usr/bin/python
- # -*- coding: UTF-8 -*-
-
- class C(object):
- @staticmethod
- def f():
- print('runoob');
-
- C.f(); # 静态方法无需实例化
- cobj = C()
- cobj.f() # 也可以实例化后调用
复制代码 以上实例输出结果为: |
论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
|
|
|
|
|
|