How to convert a string to a list?

This question already has an answer here:

  • How to create a list with the characters of a string? 4 answers

  • 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

    上一篇: python 2.7 for循环来生成一个列表

    下一篇: 如何将字符串转换为列表?