# -*- 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

 

相关文章:

  • 2021-07-08
  • 2021-11-15
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2021-12-05
  • 2021-12-26
  • 2022-12-23
猜你喜欢
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2021-12-28
  • 2022-12-23
相关资源
相似解决方案