class Echo():
def __init__(self, name):
self.name = name
print("Hello {}!".format(name))
def __len__(self):
n=0
name=self.name
for i in name:
if i.isupper()==True:
n=n+1;
print("Hello {}!".format(n))
s = input()
echoA = Echo(s)
len(echoA)
想問(wèn)一下各位,為何會(huì)報(bào)這個(gè)錯(cuò)'NoneType' object cannot be interpreted as an integer
3 回答

BIG陽(yáng)
TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
定義魔術(shù)方法 def __len__(self)
時(shí),需要返回一個(gè)數(shù)值,,,即 __len__() should return >= 0
。。你這里沒(méi)有顯示使用 return 語(yǔ)句,所以默認(rèn)返回 None
添加回答
舉報(bào)
0/150
提交
取消