Convert String To Array Python Code Example


Example 1: python string to array


>>> text = 'a b c'
>>> text = text.split(' ')
>>> text
[ 'a', 'b', 'c' ]

Example 2: convert string to list python


# To split the string at every character use the list() function
word = 'abc'
L = list(word)
L
# Output:
# ['a', 'b', 'c']

# To split the string at a specific character use the split() function
word = 'a,b,c'
L = word.split(',')
L
# Output:
# ['a', 'b', 'c']

Example 3: string to list python


s = 'hello'
l = list(s)
print(l) # prints ['h', 'e', 'l', 'l', 'o']

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android SDK Location Should Not Contain Whitespace, As This Cause Problems With NDK Tools