String Length in Python

Level 120 keystrokes

This prints the length of the string 'Python', which is 6. The len() function counts the number of characters.

Python code

# len() returns the length of an object; for a string, the number of characters
# "Python" has 6 characters (P, y, t, h, o, n), so 6 is printed
1print(len("Python"))

Output

6
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

More Python examples at level 1

← Python typing practice