1
class idk():
def __init__(self,name,age):
self.name = name
self.age = age
def t(self):
self.t = self.name + self.age
def qrt(self):
print(len(self.t))
abc = idk('abc','19')
abc.qrt()
abc.name= 'aduhd'
abc.qrt()
當我運行此代碼我碰到下面的錯誤Python的OOP相關的實例變量的使用
Traceback (most recent call last):
File "C:/Users/Prajval/Desktop/test.py", line 11, in <module>
abc.qrt()
File "C:/Users/Prajval/Desktop/test.py", line 8, in qrt
print(len(self.t))
TypeError: object of type 'instancemethod' has no len()
什麼以下錯誤意味着:
TypeError: object of type 'instancemethod' has no len()
它給出了錯誤,因爲變量't'不存在 – Yorian