__init__里面的name字段为普通字段,为每个对象都有的
cc = 123为静态字段,为类自己的,多个对象共有静态字段,比普通字段更省内存
静态字段在代码加载时,已经创建,普通字段只有在对象创建时,才会创建
一般情况下都是自己访问自己的字段,对象访问对象的字段,类访问类的字段
Python中对象也可以访问静态字段,但是有些像Java的,是类自己才能访问
最好是秉承这样的规则:普通字段只能对象来访问,静态字段只能用类来访问
普通方法:对象来调用,最常使用
静态方法:staticmethod 在def上面得声明,@staticmethod, 只能类自己来调用,不依赖对象就可以调用,省内存
静态方法其实就等于python的函数
类方法:classmethod 在def上面得声明,@classmethod, 函数代码部分必须带参数cls,def fuc(cls),调用该方法的时候可以不传参数,cls默认为类名