此问题在此处已有答案:
How can I collect the results of a repeated calculation in a list, dictionary etc. (make a copy of a list with each element modified)?(2个答案)
Why do these list methods (append, sort, extend, remove, clear, reverse) return None rather than the resulting list?(6个答案)
四年前关闭了。
我试图写一个程序,将接收输入,运行一些计算,并将它们存储在一个列表中,然后添加列表的元素。但我不断得到错误:wh_list = wh_list.追加(wh)属性错误:“NoneType”对象没有属性“append”
代码:
wh_list = []
u = len(wh_list)
if u <= 1:
while True:
inp = input("Y or N:")
B = int(input("B value:"))
C = int(input("C value:"))
D = int(input("D value:"))
wh = B * C * D
wh = int(wh)
wh_list = wh_list.append(wh)
if inp == "Y":
break
else:
Ewh = sum(wh_list)
print(Ewh)
1条答案
按热度按时间0yg35tkg1#
append
更改列表并返回None
。意志
wh
追加到wh_list
None
分配给wh_list
在下一次迭代中,它将中断,因为
wh_list
不再是列表。相反,只写