Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
substring()

How to execute a string split() function in Python

Educative Answers Team

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(':')) 

RELATED TAGS

python
substring()
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring