📜  方法和属性的区别 - Python 代码示例

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

代码示例1
a = 10                          # variable

def f(b):                       # function  
    return b ** 2

class C:

    c = 20                      # class attribute

    def __init__(self, d):      # "dunder" method
        self.d = d              # instance attribute

    def show(self):             # method
        print(self.c, self.d) 

e = C(30)
e.g = 40