1. 程式人生 > >Python list 和 str 互轉

Python list 和 str 互轉

pytho str 輸出 互轉 div python post 字符串 pri

一、list轉字符串

命令:‘‘.join(list)
其中,引號中是字符之間的分割符,如“,”,“;”,“\t”等等
如:
list = [1, 2, 3, 4, 5]
‘‘.join(list) 結果即為:12345
‘,‘.join(list) 結果即為:1,2,3,4,5

二、字符串轉list

print list(‘12345‘)
輸出: [‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘]
print list(map(int, ‘12345‘))
輸出: [1, 2, 3, 4, 5]

Python list 和 str 互轉