【发布时间】:2018-03-10 08:39:09
【问题描述】:
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()
当我运行此代码时,我收到以下错误
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: 'instancemethod' 类型的对象没有 len()
【问题讨论】:
-
它给出了错误,因为变量't'不存在
标签: python-2.7 python-3.x class oop instance-variables