String Rfind in Python

Level 257 keystrokes

This finds the last occurrence of 'o' in the string from the right.

Python code

# Create a string that contains "o" twice (index 4 and index 7)
1text = "hello world"
# rfind("o") returns the index of the last "o", counted from the left
# It returns -1 if the substring is not found
2index = text.rfind("o")
# Prints 7 (the "o" in "world")
3print(index)

Output

7
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.

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

More Python examples at level 2

← Python typing practice