class Person:
def work(self):
print("努力上班!")
s=Person()
s.work()
#输出结果,努力上班!
class Person:
def work(self):
print("努力上班!")
def play(self,name):
self.name=name
print('{0}正在玩游戏'.format(name))
s=Person()
s0=Person()
s.work()
s0.play('li')
#输出结果,努力上班! li正在玩游戏
class Person:
def work(self):
print("努力上班!")
def play(m):
print('{0}正在玩游戏'.format(m))
s=Person()
s0=Person()
s.work()
s0.play('li')
#会报错,因为没有play
class Person:
def work(self):
print("努力上班!")
def play(s):
print('{0}正在玩游戏'.format(s))
n=Person()
n.work()
Person.play1=play
p=Person()
p.play1() #看好p和s的区别
#输出是努力上班! <__main__.Person object at 0x0000020644571C10>正在玩游戏