banner

© 2004-21 ict4u.net

Split a String Into Parts

The spilt method finds every occurrence of the character in the parameter creates a list of all the elements found

# A Knifton
# Demo of Python splitting a text string
#
textPara = "Etiam pretium arcu vel libero sollicitudin congue. Donec id lacus blandit, facilisis sapien quis, tincidunt nisi. Morbi sagittis nisi augue, ac lacinia elit mollis ac."

print ("Complete paragraph:\n{}\n".format( textPara))
#
# Now split the paragraph into sentences
#
textSentences=textPara.split(".")
# the spilt method finds every occurrence of the character in the parameter creates a list of all the elements found
print ("Paragraph into sentences is:\n{}".format(textSentences))