class Superman:
def __init__(self,name):
self.name=name
self.gender=1
self.signal=1
self.illness=False
def nine_negative_kungfu(self):
return 'ya!you have to die!'
zhangsan=Superman('zhangsan')
print("the superman name is:",zhangsan.name)
print("superman is(0-female,1-male)",zhangsan.gender)
result=zhangsan.nine_negative_kungfu()
print("if superman plays nine negative kungfu,the result is:")
print(result)
Traceback (most recent call last):
File "c8.py", line 1, in <module>
class Superman:
File "c8.py", line 9, in Superman
zhangsan=Superman('zhangsan')
NameError: name 'Superman' is not defined
uj5u.com熱心網友回復:
從第9行 zhangsan=Superman('zhangsan') 開始直到未尾,不應該縮進。也就是你把這些實際創建實體的陳述句寫到class陳述句內了,左側不應該有縮進,應該與class左對齊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/171478.html
