的代碼是類型錯誤:對於不支持+操作數類型(S):「功能」和「廉政」 ...需要支持
class Demo():
count = 0
def __init__(self,name, no):
Demo.count = Demo.count + 1
self.name = name
self.no = no
def display(self):
print(self.name)
print(self.no)
def count(self):
print(Demo.count)
D = Demo('Mohan',20)
D.display()
D.count()
當我運行這段代碼,我收到以下錯誤消息。
TypeError: unsupported operand type(s) for +: 'function' and 'int' Process finished with exit code 1
如何擺脫這個錯誤並利用類變量?
你已經有2個'count':變量和方法名,試着重命名其中的一個。 – SatanDmytro