Python Reference Library →

Python String rsplit() Method – Split from the Right

Let’s look at string rsplit() method – split from the right

  1. Notice

    rsplit() splits from the right when maxsplit limits the number of splits. The result is a list.

  2. Try

    Follow the example, change its sample, and compare what happens.

  3. Check

    Explain the result and test your understanding.

Watch how it works

Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.

Explore the idea

Follow the code and watch its state change. Guided simulation.

Code
Python
text = 'tea:milk:water'
result = text.rsplit(":", 1)
print(result)
Live state

Top-level scope

text→Object 1
result→Object 2
Object 1 · str'tea:milk:water'Object 2 · list['tea:milk', 'water']
This step

rsplit() splits from the right when maxsplit limits the number of splits. The result is a list.

Picture string rsplit() method – split from the right

rsplit() splits from the right when maxsplit limits the number of splits. The result is a list.

Image brief

Alt text
A diagram for Python String rsplit() Method – Split from the Right. Instructions: text = 'tea:milk:water' result = text.rsplit(":", 1) print(result). Displayed result: ['tea:milk', 'water']. The final example bindings are text --> object 1 (str); result --> object 2 (list). object 1: 'tea:milk:water'; object 2: ['tea:milk', 'water']
Image generation prompt
Create a clean educational illustration for a Python programming lesson titled "Python String rsplit() Method – Split from the Right". Teaching focus: rsplit() splits from the right when maxsplit limits the number of splits. The result is a list. Depict exactly the relationships and labels in this reference diagram: EXAMPLE INSTRUCTIONS text = 'tea:milk:water' result = text.rsplit(":", 1) print(result) | v DISPLAYED RESULT ['tea:milk', 'water'] FINAL BINDINGS text --> object 1 (str) result --> object 2 (list) object 1: 'tea:milk:water' object 2: ['tea:milk', 'water'] Use a flat vector style, generous spacing, clear arrows and legible labels, with a restrained blue/teal palette on a plain background. The diagram must explain the programming idea accurately. Do not depict variables as boxes containing copied objects when they share a reference. Avoid mascots, decorative screenshots, logos, gradients and extra text. Landscape composition, approximately 3:2, suitable for a course card. Accessible description: A diagram for Python String rsplit() Method – Split from the Right. Instructions: text = 'tea:milk:water' result = text.rsplit(":", 1) print(result). Displayed result: ['tea:milk', 'water']. The final example bindings are text --> object 1 (str); result --> object 2 (list). object 1: 'tea:milk:water'; object 2: ['tea:milk', 'water']

Follow the execution

Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
Python
text = 'tea:milk:water'
result = text.rsplit(":", 1)
print(result)
Live state

Top-level scope

text→Object 1
result→Object 2
Object 1 · str'tea:milk:water'Object 2 · list['tea:milk', 'water']
This step

The example has finished. Compare the final output with the values and references above.

Terminal
Output
['tea:milk', 'water']

What do you expect this program to print?

What does this example display?

text = 'tea:milk:water'
result = text.rsplit(":", 1)
print(result)
What does this example display?
Choose one answer. You can try again.

Answer and explanation

['tea:milk', 'water']

Follow the printed values in order. The output is: ['tea:milk', 'water']

Which explanation matches what you learned?

Which explanation matches what you learned?
Choose one answer. You can try again.

Answer and explanation

rsplit() splits from the right when maxsplit limits the number of splits. The result is a list.

rsplit() splits from the right when maxsplit limits the number of splits. The result is a list.

More examples and reference

Python String rsplit() Method

The rsplit() method in Python is used to split a string from the right. It returns a list of substrings, just like split(), but starts splitting from the end of the string.

Syntax

string.rsplit([separator[, maxsplit]])

Parameters:

  • separator (optional): The delimiter on which to split the string. If not provided, any whitespace is considered as the separator.
  • maxsplit (optional): Maximum number of splits. The splitting starts from the right.

Returns:

  • A list of strings after splitting.

Example 1: Basic Usage of rsplit()

text = "apple,banana,cherry"
result = text.rsplit(",")
print(result)
['apple', 'banana', 'cherry']

Example 2: Using maxsplit

text = "apple,banana,cherry"
result = text.rsplit(",", 1)
print(result)
['apple,banana', 'cherry']

Here, only 1 split is done, and it starts from the right.

Example 3: Without Separator (Splits on Whitespace)

text = "Python is beginner friendly"
result = text.rsplit()
print(result)
['Python', 'is', 'beginner', 'friendly']

Key Differences: split() vs rsplit()

  • split() splits from the left (start).
  • rsplit() splits from the right (end).
  • Both accept the same parameters and return a list.

Use Cases

  • When you only want to split the last few items in a string.
  • Parsing file paths, logs, or reversed values.

Common Mistakes

  • Forgetting that maxsplit works from the right.
  • Expecting rsplit() to modify the string (it returns a new list).

Practice Problem

Split the string "2025-05-14" into day, month, and year using rsplit("-", 1). What will be the result?

date = "2025-05-14"
print(date.rsplit("-", 1))

Expected Output:

['2025-05', '14']

Summary

  • rsplit() splits a string into a list, starting from the right.
  • Use maxsplit to control how many splits you want.
  • If no separator is given, whitespace is used.

What to remember

Connect what you noticed in the example with the idea below.

Remember

rsplit() splits from the right when maxsplit limits the number of splits. The result is a list.

Watch out for this idea

rsplit(sep, 1) chooses the leftmost separator.

This is the misconception to avoid.

Reference checks are optional and do not count toward course progress.

    Reference library →