绑定对象

绑定方法

定义在类内部的方法:

如果类来调用:就是一个普通函数,有几个参数就需要传几个参数

对象来调用:它叫对象的绑定方法,第一个参数不需要传,自动传递

class Student:
    school='xxx'
    def __init__(self,name):
        self.name=name
    def choose(self):
        print('选课...')
    def study(self):
        print(f'{self.name}学会了python')
        
stu1=Student('nick')
stu1.study()
stu1=Student('李铁蛋')
stu1.study()

nick学会了python
李铁蛋学会了python

原文地址:https://www.cnblogs.com/aden668/p/11413029.html