String Replace in Python

Level 132 keystrokes

This replaces 'i' with 'ello' in 'Hi'. The replace() method returns a new string with replacements made.

Python code

# replace(old, new) returns a new string with every old replaced by new
# Replacing "i" in "Hi" with "ello" gives "Hello"
1print("Hi".replace("i", "ello"))

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.

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

More Python examples at level 1

← Python typing practice