How to convert a string to a list?
This question already has an answer here:
A string is an iterable, and a list can be constructed from an iterable. So all you need is
a = list(a)
print(a)
Output:
['h', 'e', 'l', 'l', 'o']
Tried to do it differently
Code:
map(None,"sart")#for python 2.x
#list(map(None,"sart")) for python 3.x
Output:
['s', 'a', 'r', 't']
链接地址: http://www.djcxy.com/p/69958.html
下一篇: 如何将字符串转换为列表?