📜  构造函数 python 变量 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:51.573000             🧑  作者: Mango

代码示例1
class DemoClass:
    num = 101 # default value of self.num when read_number method called

    # parameterized constructor
    def __init__(self, data):
        self.num = data

    # a method
    def read_number(self):
        print(self.num)