How to split a string into an array of characters in Python?

前端 未结 13 1231
一整个雨季
一整个雨季 2020-11-22 01:54

I\'ve tried to look around the web for answers to splitting a string into an array of characters but I can\'t seem to find a simple method

str.split(//)

相关标签:
13条回答
  • 2020-11-22 02:31

    Well, much as I like the list(s) version, here's another more verbose way I found (but it's cool so I thought I'd add it to the fray):

    >>> text = "My hovercraft is full of eels"
    >>> [text[i] for i in range(len(text))]
    ['M', 'y', ' ', 'h', 'o', 'v', 'e', 'r', 'c', 'r', 'a', 'f', 't', ' ', 'i', 's', ' ', 'f', 'u', 'l', 'l', ' ', 'o', 'f', ' ', 'e', 'e', 'l', 's']
    
    0 讨论(0)
提交回复
热议问题