Answers for "split a string based on words python"

10

python split sentence into words

sentence = 'Hello world a b c'
split_sentence = sentence.split(' ')
print(split_sentence)
Posted by: Guest on October-12-2020
1

split a string into an array of words in python

string = '1-2-3
array_of_words = string.split('-')
print(array_of_words)    # prints ['1', '2', '3']
##################################################
#if you dont pass anything in the split() function,
#the default parameter will be a space
##################################################
string = '1 2 3'
array_of_words = string.split()
print(array_of_words)    # prints ['1', '2', '3']
Posted by: Guest on September-30-2021

Code answers related to "split a string based on words python"

Python Answers by Framework

Browse Popular Code Answers by Language