Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to get each word in a string in python

# Python3 code to demonstrate
# to extract words from string
# using regex( findall() )
import re
 
# initializing string 
test_string = "Geeksforgeeks,    is best @# Computer Science Portal.!!!"
 
# printing original string
print ("The original string is : " +  test_string)
 
# using regex( findall() )
# to extract words from string
res = re.findall(r'w+', test_string)
 
# printing result
print ("The list of words is : " +  str(res))

#Output>>> [‘Geeksforgeeks’, ‘is’, ‘best’, ‘Computer’, ‘Science’, ‘Portal’]
 
PREVIOUS NEXT
Tagged: #word #string #python
ADD COMMENT
Topic
Name
1+5 =