課程
/后端開發
/Python
/python進階
代碼無法提交,運行處理的結果只有Bob,并沒有
Traceback (most recent call last):? File "<stdin>", line 1, in <module>AttributeError: 'Person' object has no attribute '__score'
2015-12-16
源自:python進階 4-5
正在回答
你這個是什么IDE?
class Person(object):
? ? def __init__(self, name, score):
? ? ? ? self.name=name
? ? ? ? self.__score=score
p = Person('Bob', 59)
print (p.name)
try:
? ? print (p.__score) ? ?
except AttributeError:
? ? print'AttributeError'
上面的代碼是正確的,你試試。
史高武
因為答案非要匹配這個AttributeErro報錯信息,但這個自帶的編譯不會有這個結果。所以不讓你通過
你可以加個運行錯誤,就print?AttributeErro 就可以了
以你自己的編譯器為準,有的章節的在線編譯器有點小的BUG,只要你能理解這個知識點就好了
舉報
學習函數式、模塊和面向對象編程,掌握Python高級程序設計
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-03-14
你這個是什么IDE?
2016-09-12
class Person(object):
? ? def __init__(self, name, score):
? ? ? ? self.name=name
? ? ? ? self.__score=score
p = Person('Bob', 59)
print (p.name)
try:
? ? print (p.__score) ? ?
except AttributeError:
? ? print'AttributeError'
上面的代碼是正確的,你試試。
2016-05-01
因為答案非要匹配這個AttributeErro報錯信息,但這個自帶的編譯不會有這個結果。所以不讓你通過
你可以加個運行錯誤,就print?AttributeErro 就可以了
2015-12-16
以你自己的編譯器為準,有的章節的在線編譯器有點小的BUG,只要你能理解這個知識點就好了