user469104
0
Q:

how to split a string by character in python

def split(word): 
    return [char for char in word]  
      
# Driver code 
word = 'geeks'
print(split(word)) 

#Output ['g', 'e', 'e', 'k', 's']
10
# Default splits at whitespace
txt = "Welcome to the jungle, baby!"
txt.split()
# Output:
# ["Welcome", "to", "the", "jungle," "baby!"]

# You can specify where to split
txt = "Welcome to the jungle, baby!"
txt.split(", ")
# Output:
# ["Welcome to the jungle", "baby!"]
72
def split(word): 
    return [char for char in word]
1
>>> txt = "hello, my name is Peter, I am 26 years old"

>>> x = txt.split(", ")

>>> print(x)
["hello", "my name is Peter", "I am 26 years old"]
3
# Python3 program to Split string into characters 
def split(word): 
    return [char for char in word]  
      
# Driver code 
word = 'geeks'
print(split(word)) 
1
>>> "MATCHES__STRING".split("__")
['MATCHES', 'STRING']
1

New to Communities?

Join the community