String Count in Python

Level 126 keystrokes

This counts occurrences of a substring. The count() method returns how many times a substring appears.

Python code

# count() returns how many times a substring appears in the string
# "banana" contains "a" three times, so 3 is printed
1print("banana".count("a"))

Output

3
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
  • .× 1

More Python examples at level 1

← Python typing practice