美文网首页python的记录
Python List 和Str 的相互转换

Python List 和Str 的相互转换

作者: JP0001 | 来源:发表于2022-03-25 08:47 被阅读0次
list==》str
list1=['two','three']
print(''.join(list1))# list 包含int 的话这个就不能使用  =>twothree
list2=['two',222,'three']
print(''.join([str(i) for i in list2]))# list 包含int 的话这个就不能使用  => two222three

mystr='asdfasdfasdfasdfs'
list1 = list(mystr)
print(list1)# ['a', 's', 'd', 'f', 'a', 's', 'd', 'f', 'a', 's', 'd', 'f', 'a', 's', 'd', 'f', 's']


相关文章

网友评论

    本文标题:Python List 和Str 的相互转换

    本文链接:https://www.haomeiwen.com/subject/mrbpdrtx.html