Re: [問題] 再問一個設定variable的問題

看板Python作者 (酷狗喵千代)時間17年前 (2008/05/06 10:33), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/5 (看更多)
※ 引述《azulazure (azul)》之銘言: : 如果說有一個像這樣的語法 : counter = 0 : for item in [0, 1, 2]: : counter += item : print counter : 這樣是可以得到結果 : 但如果我想要在之後再次使用這個數字怎麼辦? : 我要如何設定一個variable, i.e., "num" : 使得num = "counter += item" ?? : 一副就是很新手的問題... 其實我看不太懂你的問題 :p 如果有什麼東西之後還要用,就該取個名字: counter = 0 items = [0,1,2] for item in items: counter += item print counter, items -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 164.107.248.238 ※ 編輯: yungyuc 來自: 164.107.248.238 (05/06 10:33)
文章代碼(AID): #187yDTl_ (Python)
文章代碼(AID): #187yDTl_ (Python)