list问题
list1=[]i=1
while i!=0:
i=eval(input("shuru:"))
list1.append(i)
list2=list1.reverse()
for i in range(len(list2)):
print(list2)
运行后,输入“0”后,会出现“TypeError: object of type 'NoneType' has no len()”为什么? 列表的大部分方法都是在原列表上操作,不会有返回值。
详情请见:https://fishc.com.cn/thread-159315-1-1.html
你的代码应该这样改:
list1 = []
i = 1
while i != 0:
i = eval(input("shuru:"))
list1.append(i)
list1.reverse()
for i in range(len(list1)):
print(list2)
页:
[1]