How to convert a string with comma-delimited items to a list in Python?

后端 未结 14 639
予麋鹿
予麋鹿 2020-11-28 03:09

How do you convert a string into a list?

Say the string is like text = \"a,b,c\". After the conversion, text == [\'a\', \'b\', \'c\'] and h

14条回答
  •  攒了一身酷
    2020-11-28 04:03

    Example 1

    >>> email= "myemailid@gmail.com"
    >>> email.split()
    #OUTPUT
    ["myemailid@gmail.com"]
    

    Example 2

    >>> email= "myemailid@gmail.com, someonsemailid@gmail.com"
    >>> email.split(',')
    #OUTPUT
    ["myemailid@gmail.com", "someonsemailid@gmail.com"]
    

提交回复
热议问题