[問題] 'NoneType' object is not iterable?

看板Python作者 (無價)時間16年前 (2009/02/22 12:07), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
我是從 C++ 轉到 python 這邊來的 一開始有點不習慣的是 function 的 argument 並未指定型別 所以今天碰到了這個問題 傳入一個我認為是 list 的東西 但 python 跟我說這是 non-iterable code: ======================= def sd_calculation(component_vector): # calculate the average for x in component_vector: sum += x average = sum / len(component_vector) print average ======================= error msg: 'NoneType' object is not iterable 想請教一下各位板友這該如何解決? 還是說 argument 型別是動態型別 我是真的不小心傳入了一個 non-iterable 的 object? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.160.39.186

02/22 12:12, , 1F
原來是動態決定的 我不小心傳錯東西了 @@
02/22 12:12, 1F
文章代碼(AID): #19eC-MB3 (Python)
文章代碼(AID): #19eC-MB3 (Python)