1. 程式人生 > >Python--self總結

Python--self總結

post sel learn () print __init__ skill kill --

class My(object):
def __init__(self, name, skill):
self.name = name
self.skill = skill
self.cry()

def cry(self): # 實例方法,必須實例化之後才可以調用
print(‘%s在哭。。。‘ % self.name)

def learn(self):
self.skill = [‘開車‘]

def my_self(self):
print(‘我的名字是%s,我會%s‘ % (self.name, self.skill))


wsl = My(‘老虎‘, [‘跑步‘]) # self = wsl
wsl.skill = ‘浪‘
wsl.learn()
wsl.my_self()

Python--self總結