How to use split function in Python

The split() function is used to split the string at specified separator and returns a list of strings
Syntax: list_name.split(separator[,max])
separator
– an optional delimiter. The string splits at the specified separator. The default value of split if any whitespace.max
– optional. Defines the maximum number of splits. Default value is -1, that is no limit to splits
Example:
str = "Pythonpoint is awesome" #splits at whitespace. default case print(str.split()) numbers = "1, 2, 3, 4, 5" #splits at ',' print(numbers.split(','))
Output:
['Pythonpoint', 'is', 'awesome'] ['1', ' 2', ' 3', ' 4', ' 5']
Subscribe
Login
Please login to comment
0 Discussion