类方法,静态方法,普通方法

#coding=utf-8

 

class Foo:

    def __init__(self,name):

        self.name=name

 

    def ord_func(self):

        print self.name

        print "normal function"

 

    @classmethod

    def class_func(cls):

        print "class method"

 

    @staticmethod

    def static_func():

        print "static method"

 

f=Foo('xiaxiaoxu')

f.ord_func()

Foo.class_func()

 

Foo.static_func()

c:\Python27\Scripts>python task_test.py

xiaxiaoxu

normal function

class method

static method

相关文章:

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