2015-05-04 140 views
-3
ClassNames = studentname and score 
if studentname not in ClassNames: 
    ClassNames = ClassNames.append(studentname) 
for studentname in filename and ClassNames <= 3: 
    FirstResult.append(score) 
    SecondResult.append|(score) 
    ThirdResult.append(score) 

if行給我的錯誤:TypeError:類型'int'的參數不可迭代?這是什麼意思?

TypeError: argument of type 'int' is not iterable 
+1

'類名= studentname和score' - 你有什麼期望去做? – user2357112

+0

你能指定一個你用於'studentname'和'score'的內容的例子嗎? –

回答

1
ClassNames = studentname and score 

最有可能將變量ClassNamesscore這聽起來像它可能由int

通過調用

if studentname not in ClassNames: 
    ... 

您通過ClassNames迭代找到studentname,但像你的錯誤說:int不迭代。

進一步的問題:

  1. list.append()就地工作,並返回None
  2. ClassNames <= 3也只感,如果它是一個int
+0

謝謝!如果ClassNames <= 3只有在int時纔有意義,我可以使用什麼呢? – bols

+0

您可能想看看['dict'](https://docs.python.org/2/library/stdtypes.html#mapping-types-dict)。 – tynn

-1

ClassName是布爾運算的結果,所以它可以採取值True或False(0或1)。因爲它是不可迭代的類型,所以你得到這個錯誤。

重新考慮想要保存在ClassName中的數據。

+0

這在[Python]中不正確(https://docs.python.org/2/library/stdtypes.html#boolean-operations-and-or-not)。 – tynn

相關問題