Answers for "how to separate words in a string in python"

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
4

how to split word in python

text= "I am Batman"
splitted_text= text.split()

Print(splitted_text)
Posted by: Guest on September-02-2020

Code answers related to "how to separate words in a string in python"

Python Answers by Framework

Browse Popular Code Answers by Language