我有與上述列表:如何字符串轉換成整數的python sickit學習
probs= ['2','3','5','6']
,我想這些字符串轉換爲數值類似下面的結果:
resultat=[2, 3, 4, 5, 6]
我試過出現此鏈接一些解決方案: How to convert strings into integers in Python? 像這樣的:
new_list = list(list(int(a) for a in b) for b in probs if a.isdigit())
但它沒有工作,有人可以幫助我適應這個功能在我的數據結構上,我會非常感激。
'resultat = [INT(項目)的項目在probs]'? – mgilson
只是語法問題。您正在創建一個列表清單。相反,使用: 'new_list = list(int(a)for a probs if a.isdigit())' – user1952500