How to use split in python?

The split() method separates the string by the given separator and returns the lists of string.
By default, split() takes whitespace as a delimiter.
e.g.,
s=" Python is a famous programming language" a=s.split() for temp in a: print(temp)
output- python is a famous programming language
Parameters
- 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.
e.g.,
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.
Subscribe
Login
Please login to comment
0 Discussion