Home >>Python String Methods >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 | 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. |
txt = "welcome to PHPTPOINT"
x = txt.split()
print(x)
txt = "hello, my name is Jerry, I am 21 years old"
x = txt.split(", ")
print(x)