Splitting a string in Python is really easy.

You simply take a string and apply the split() method.

"Your String".split()

See some examples of the Python Split String method:

A Python Split String – Example

1
2
3
4
5
6
7
8
# Your string
a_string = "This is our string"

# Split into a list
a_list = a_string.split()

# Print the list
print(a_list)

Python Split String – Syntax

1
string.split(separator, maxsplit)

Parameter Values

Parameter Description
separator Optional – What to split the string on. The default is the whitespace character
maxsplit Optional – How many splits to perform. The default is -1, meaning “no limit”

Some examples for Python Split String

Use a comma (,) as the separator:

1
2
3
4
5
6
7
8
# Your string
a_string = "This, is, our, string"

# Split into a list
a_list = a_string.split(", ")

# Print the list
print(a_list)

Use a pipe (|) as the separator:

1
2
3
4
5
6
7
8
# Your string
a_string = "This|is|our|string"

# Split into a list
a_list = a_string.split("|")

# Print the list
print(a_list)