NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
#### 实例方法、静态方法和类方法 ~~~ class Person(object): # 实例方法,至少一个self参数 def obj_method(self): print("person obj_method ...") # 类方法,至少一个cls参数 @classmethod def cls_method(cls): print("person cls_method ...") # 静态方法,无默认参数 @staticmethod def static_method(): print("person static_method ...") person = Person() person.obj_method() Person.cls_method() Person.static_method() ~~~ ``` 三种方法在内存中都归属于类,区别在于调用方式不同 * 相同点:对于所有的方法而言,均属于类,所以 在内存中也只保存一份 * 不同点:方法调用者不同、调用方法时自动传入的参数不同 ```