Student Handbook

Student Handbook

Open in ChatGPT
Ask ChatGPT about this page
Open in Claude
Ask Claude about this page

str.split

Breaks a string into a list of parts.

Synopsis

text.split()
text.split(separator)

Description

Without a separator, split breaks the string at spaces and drops the spaces.

Parameters

Name Meaning
separator The text to split at. Optional. The default is any whitespace.

Return value

A list of strings.

Example

print("hello big world".split())
print("2026-10-05".split("-"))
first, last = input("Full name: ").split()
print(last)

It prints:

['hello', 'big', 'world']
['2026', '10', '05']
Full name: Ada Lovelace
Lovelace

Common mistake

first, last = input("Full name: ").split()

Python stops with:

Full name: Ada
ValueError: not enough values to unpack (expected 2, got 1)

One word gives a list of one part, but the line asks for two. Check len(...) before unpacking.

See also

str.join, str.strip, len

str.split in the Python documentation

Last updated 2 weeks ago