Strip Trailing Spaces in Python

Level 122 keystrokes

This removes trailing whitespace from a string using rstrip().

Python code

# rstrip() returns a copy with trailing (right-side) whitespace removed
# The two spaces after "hi" are dropped, so hi is printed
1print("hi ".rstrip())

Output

hi
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • "× 2
  • (× 2
  • )× 2
  • .× 1

More Python examples at level 1

← Python typing practice