How to execute a string split() function in Python

The Python split() method takes a specified delimiter, breaks the string at that point, and returns that list of strings.

svg viewer

Syntax

str.split(separator, maxsplit)

Parameters

Delimiter (or separator): A string splits at this specified delimiter.

Note: white space is a default separator here.

Maxsplit: Specifies the maximum number of times that the string should be split.

Output: A list of strings.

Code

The following code gives an example of splitting strings in python. All three examples, given in the code snippet, output two strings, ‘hello’ and ‘world’.

text = 'hello world'
# Splits at space
print(text.split())
text = 'hello, world'
# Splits at ','
print(text.split(', '))
text = 'hello:world'
# Splitting at ':'
print(text.split(':'))

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved