# 类方法
# 如果 该class 没有要继承的类 则一般需要继承 object 基类


class ClassMethodBase(object):
    # 起手初始化 以示尊敬
    def __init__(self, name):
        # 定义类属性
        self.name = name

    # 定义类方法
    # self 就是 对象/实例 属性的集合,
    def class_base(self):
        """这是文档字符串"""
        print("hello word")
        return "什么东西"


if __name__ == '__main__':
    # 实例化 对象 ClassMethodBase
    Base = ClassMethodBase(name='我怕')
    # 调用 类方法
    a = Base.class_base()
    print(a)  # 什么东西

相关文章:

  • 2022-01-20
  • 2019-08-22
  • 2022-12-23
  • 2022-01-11
  • 2021-11-30
  • 2021-09-30
  • 2022-01-16
  • 2021-12-10
猜你喜欢
  • 2021-10-08
  • 2021-07-11
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2021-10-21
  • 2018-10-22
相关资源
相似解决方案