标签:指针 code setname xxx span ++ 面向对象 int c++
self
#self 是相当于c++的 this指针 class Ball: def setName(self,name): self.name = name def kick(self): print(‘我叫%s‘%self.name) ball = Ball() ball.setName(‘足球‘) ball.kick() ball1 = Ball() ball1.setName(‘篮球‘) ball1.kick() class Ball1: def __init__(self,name,id=‘xxx‘):#构造函数,初始化实例对象的时候 会自动调用 self.name = name self.id = id def kick(self): print(‘我叫%s,我是世界第%s大球‘%(self.name,self.id)) b = Ball1(‘排球‘,‘三‘) b.kick()
标签:指针 code setname xxx span ++ 面向对象 int c++
原文地址:https://www.cnblogs.com/mhmh007/p/11837142.html