类的另外的特性,装饰器方法:静态方法(staticmethod)、类方法(classmethod)、属性方法(property)

1、静态方法

在方法名前加上@staticmethod装饰器,表示此方法为静态方法

class Dog(object):

    def __init__(self, name):
        self.name = name

    @staticmethod  # 在方法前加上staticmethod 装饰器定义静态方法
    def eat():
        print("dog is eating")
View Code

相关文章:

  • 2021-09-06
  • 2022-12-23
  • 2022-01-12
  • 2021-11-07
  • 2021-07-09
  • 2022-01-02
  • 2022-12-23
  • 2021-09-26
猜你喜欢
  • 2021-07-11
  • 2022-01-24
  • 2021-09-23
  • 2021-07-28
  • 2021-06-08
  • 2021-08-19
相关资源
相似解决方案