Answers for "split a string on a specific character python"

26

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']
Posted by: Guest on December-07-2019
1

python split every character in string

def split(word): 
    return [char for char in word]
Posted by: Guest on September-21-2020
0

python split string by specific word

>>> mary = 'Mary had a little lamb'
>>> mary.split('a')                 # splits on 'a'
['M', 'ry h', 'd ', ' little l', 'mb'] 
>>> hi = 'Hello mother,nHello father.'
>>> print(hi)
Hello mother,
Hello father. 
>>> hi.split()                # no parameter given: splits on whitespace
['Hello', 'mother,', 'Hello', 'father.'] 
>>> hi.split('n')                 # splits on 'n' only
['Hello mother,', 'Hello father.']
Posted by: Guest on October-26-2021

Code answers related to "split a string on a specific character python"

Python Answers by Framework

Browse Popular Code Answers by Language