python "".join() 出錯TypeError: sequence item 0: expected string, int found


python中使用join連接list時出現類型錯誤的解決辦法

例:
>>> ls = [1,2,3]
>>> print ','.join(ls)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected string, int found

解決辦法對list中的元素進行類型轉換到string

>>> print ','.join('%s' % id for id in ls)
1,2,3

 

ref : http://hi.baidu.com/zhumq92/item/3e58dd395c4b040dcfb9fe62


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM