The split() method separates the string by the given separator and returns the lists of string.
By default, split() takes whitespace as a delimiter.
s=" Python is a famous programming language" a=s.split() for temp in a: print(temp)
output- python is a famous programming language
- Separators:-String splits at this specified separator.
- maxsplit:- It is a number, which tells us to split the string into maximum of provided number of times. If it is not provided then there is no limit.
s="Have#a#good#day" a=s.split("#",2) for temp in a: print(temp)
output- Have a good#day
This is how we use split function in python.