How to split a string in Python

Python provides a function named split() which can be used to achieve this. It also provides a way to control the delimiter and number of characters to be considered as delimiter

 

Example

str = "Python Java PHP Flutter";
print(str.split())
print(str.split(' ', 2))

 

This will return below output

['Python', 'Java', 'PHP', 'Flutter']
['Python', 'Java', ' PHP Flutter']