python中list和字符串相互转换

1、list转字符串

命令:''.join(list)

其中,引号中是字符之间的分割符,如“,”,“;”,“\t”等等

如:

list = [1, 2, 3, 4, 5]

''.join(list) 结果即为:12345

','.join(list) 结果即为:1,2,3,4,5

2、字符串转list

命令:str.split(",")

如:

mStr ='192.168.1.1,192.168.1.2,192.168.1.3'

print(mStr.split(","))

['192.168.1.1','192.168.1.2','192.168.1.3']

你可能感兴趣的:(python中list和字符串相互转换)