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

前端 未结 13 1515
一整个雨季
一整个雨季 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:25

    split() inbuilt function will only separate the value on the basis of certain condition but in the single word, it cannot fulfill the condition. So, it can be solved with the help of list(). It internally calls the Array and it will store the value on the basis of an array.

    Suppose,

    a = "bottle"
    a.split() // will only return the word but not split the every single char.
    
    a = "bottle"
    list(a) // will separate ['b','o','t','t','l','e']
    

提交回复
热议问题