|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
>>> class Ball:
def setname(self,name):
self,name = name
def kick(self):
print("我叫%s,该死的,谁踢我..." % self.name)
>>> a = Ball()
>>> a.setName('球A')
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
a.setName('球A')
AttributeError: 'Ball' object has no attribute 'setName'
>>> a.setname('球A')
>>> b = Ball()
>>> b.setname('球B')
>>> c = Ball()
>>> c.setname('土豆')
>>> a.kuck()
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
a.kuck()
AttributeError: 'Ball' object has no attribute 'kuck'
>>> a.kick()
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
a.kick()
File "<pyshell#1>", line 5, in kick
print("我叫%s,该死的,谁踢我..." % self.name)
AttributeError: 'Ball' object has no attribute 'name'
>>> c.kick()
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
c.kick()
File "<pyshell#1>", line 5, in kick
print("我叫%s,该死的,谁踢我..." % self.name)
AttributeError: 'Ball' object has no attribute 'name'
>>> a = Ball()
>>> a.setName('球A')
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
a.setName('球A')
AttributeError: 'Ball' object has no attribute 'setName' ----类中是setname,调用的是setName,大小写不同
>>> a.setname('球A')
>>> b = Ball()
>>> b.setname('球B')
>>> c = Ball()
>>> c.setname('土豆')
>>> a.kuck()
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
a.kuck()
AttributeError: 'Ball' object has no attribute 'kuck' ----拼写错误kuck, kick
>>> a.kick()
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
a.kick()
File "<pyshell#1>", line 5, in kick
print("我叫%s,该死的,谁踢我..." % self.name)
AttributeError: 'Ball' object has no attribute 'name' ---- 第三行 self,name = name,逗号改为点
>>> c.kick()
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
c.kick()
File "<pyshell#1>", line 5, in kick
print("我叫%s,该死的,谁踢我..." % self.name)
AttributeError: 'Ball' object has no attribute 'name' -- 同上
|
|