Swap Case in Python

Level 125 keystrokes

This swaps uppercase and lowercase letters. The swapcase() method inverts the case of each character.

Python code

# swapcase() returns a copy with uppercase and lowercase letters swapped
# H→h, e→E, LL→ll, o→O, so "hEllO" is printed
1print("HeLLo".swapcase())

Output

hEllO
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