💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
#### 实例方法、静态方法和类方法 ~~~ 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() ~~~ ``` 三种方法在内存中都归属于类,区别在于调用方式不同 * 相同点:对于所有的方法而言,均属于类,所以 在内存中也只保存一份 * 不同点:方法调用者不同、调用方法时自动传入的参数不同 ```