class Player1:
base_HP = 300
def getBHP(self):
return self.base_HP
jogador1 = Player1
jogador1_hp = jogador1.getBHP() #Functions and Class calls must end with brackets.
print(jogador1_hp)
這就是我用來獲取播放器HP的代碼,我想將它保存在jogador1_hp中。使用類內的return語句從類中獲取值
如何過這是IAM越來越:
C:\Users\joaol\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/joaol/PycharmProjects/FirstProgram/Main.py
<function Player1.getBHP at 0x02C131E0>
Process finished with exit code 0
即使我下面做,我仍然得到一個空白控制檯。編輯:我修復它,我只需要添加「()」,當我創建對象!
jogador1 = Player1()
jogador1_hp = jogador1.getBHP()
是的,那是一個愚蠢的錯誤! –