Decorator 2
常用修饰器
>>> class MyClass(): ... def thisIsClassMethod(self): ... print ("this is a class method") ... >>> MyClass().thisIsClassMethod() this is a class method >>> MyClass.thisIsClassMethod() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: thisIsClassMethod() missing 1 required positional argument: 'self'>>> class vc: ... def te(self): ... print('test') ... >>> vc.te() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: te() missing 1 required positional argument: 'self' >>> vc.te(0) test 虽然可以调用但是无任何意义>>> class xc: ... @classmethod ... def cv(self): ... print('Direct use') ... >>> xc.cv() Direct use
类的私有和公有
类的私有属性
类的方法
类的私有方法
实例
实例
单下划线、双下划线、头尾双下划线说明:
Last updated