Home >>Python String Methods >Python String split() Method

Python String split() Method

Python String split() Method

Python string split() method is used to split the given input string into a list. You can also specify the separator but the default separator is any whitespace.

Syntax:
string.split(separator, maxsplit)

Parameter Values

Parameter Description
separator This is an optional parameter. It defines the separator to use when splitting the string.
maxsplit This is an optional parameter. It defines how many splits to do.
Here is an example of Python split() method:

txt = "welcome to PHPTPOINT"
x = txt.split()
print(x)

Output:
['welcome', 'to', 'PHPTPOINT']
Example 2:

txt = "hello, my name is Jerry, I am 21 years old"
x = txt.split(", ")
print(x)

Output:
['hello', 'my name is Jerry', 'I am 21 years old']

No Sidebar ads