Python 对象方法参数self

Python 对象方法参数self

self 代表需要传递一个 对象(当前对象)作为参数

 

class A:
    def play(self)
        print('playing')

    def begin(self)
        print(begin)
        self.play() # self为当前对象

dog = A()

dog.play()
A.play(dog) # 使用类名调用方法需要传递一个对象作为self值
posted @ 2021-12-09 01:38  RChang  阅读(186)  评论(0)    收藏  举报