亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python如何在循環中填充列表

python如何在循環中填充列表

慕斯709654 2021-06-13 09:04:08
我正在嘗試編寫一個程序,該程序將接收輸入、運行一些計算并將它們存儲在列表中,然后再添加列表的元素。但我不斷收到錯誤:wh_list = wh_list.append(wh) AttributeError: 'NoneType' object has no attribute '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":            breakelse:    Ewh = sum(wh_list)    print(Ewh)
查看完整描述

1 回答

?
交互式愛情

TA貢獻1712條經驗 獲得超3個贊

append更改列表并返回None. 因此,

wh_list = wh_list.append(wh)

將要

  • 附加whwh_list

  • 分配Nonewh_list

在下一次迭代中,它將中斷,wh_list不再是列表。

相反,只寫

wh_list.append(wh)


查看完整回答
反對 回復 2021-06-15
  • 1 回答
  • 0 關注
  • 234 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號