我無法將具有字符串的列表轉換爲整數。無法將列表字符串轉換爲整數
num = ['123']
當我嘗試:
print(int(num))
我得到錯誤:
TypeError: int() argument must be a string, a bytes-like object or a number,
not 'list'
當我嘗試:
print(int(str(num)))
我得到錯誤:
ValueError: invalid literal for int() with base 10: "['123']"
您不能將列表轉換爲整數,但可以將列表中的字符串值轉換爲整數。 – Matthias
通過使用'int(num [0])' – DavidG
請注意,您也可能無法轉換'num = set(['123'])':)嘗試和錯誤不是解決問題的最佳方法。 –