# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#python之函数用法staticmethod
#http://www.cnblogs.com/hongfei/p/3858256.html #@staticmethod:Return a static method for function.
#函数的静态方法,个人以为尽可能少用该方法
#静态方法在类的内部使用,写在类的定义里面,staticmethod写在函数上方,第一个参数不是self,一般不直接在外部调用,只是在内部使用而已。
class C():
@staticmethod
def f(x):
return x c=C()
print c.f('xiaodeng')#xiaodeng #2、没有静态方法的写法如下:
class C():
def f(self,x):
return x c=C()
print c.f('xiaodeng')#xiaodeng
相关文章
- Python之函数(一)定义函数以及传参
- python中setup函数的用法_python学习之setUp函数和tearDown函数
- python标准库math中计算平方根的函数_16 Python 标准库之 math 模块 - Python 进阶应用教程...
- python中pow的意思_python中pow函数用法及功能说明
- python学习之函数返回值
- Python之函数的递归、匿名函数、内置函数
- python学习之--自定义函数:
- python中bool函数用法_在python中bool函数的取值方法
- python中content的用法_python中append函数用法讲解
- python中xticks函数_基于matplotlib xticks用法详解