小白教程
所有教程
关于
Search
172.69.59.48
172.69.59.48
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python func staticmethod”的源代码
本页内容
上一节:
Python3_func_oct
下一节:
Python_func_bin
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:staticmethod()}}[[Category:python3 built in functions|19]] = Python staticmethod() 函数 = [[python built in functions|Python 内置函数]] python staticmethod 返回函数的静态方法。 该方法不强制要求传递参数,如下声明一个静态方法: <sample title="" desc="" lang="python" hererun="1"> class C(object): @staticmethod def f(arg1, arg2, ...): ... </sample> 以上实例声明了静态方法 '''f''',从而可以实现实例化使用 C().f(),当然也可以不实例化调用该方法 C.f()。 === 函数语法 === <sample title="" desc="" lang="python" hererun="1"> staticmethod(function) </sample> 参数说明: * 无 == <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python # -*- coding: UTF-8 -*- class C(object): @staticmethod def f(): print('xiaobai'); C.f(); # 静态方法无需实例化 cobj = C() cobj.f() # 也可以实例化后调用 </sample> 以上实例输出结果为: <sample title="" desc="" lang="python" hererun="1"> xiaobai xiaobai </sample> [[python built in functions|Python 内置函数]]
返回至“
Python func staticmethod
”。
上一节:
Python3_func_oct
下一节:
Python_func_bin