python object oriented --self

self:
Which method of an object called, self is a reference (point to the object memory address space) which object of
programmers do not need to pass self argument when calling the method (defined when the first argument must be self)

class Cat:
    def eat(self):
        print('%s 爱吃鱼' %(self.name))
    def drink(self):
        print('猫要喝水')

hellokitty = Cat()
hellokitty.name = 'HK'
hellokitty.eat()
hellokitty.drink()

Here Insert Picture Description

Published 103 original articles · won praise 1 · views 942

Guess you like

Origin blog.csdn.net/qq_45652989/article/details/104280930