Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / String Manipulation

String length

All topicsPractise exam questions
Knowledge organiser

String Manipulation

301.11a

Measure size of string.

What you need to know

len() returns the number of characters in a string, including spaces and punctuation. It is commonly used for validation and loop control.

Key points

  • len("hello") → 5
  • Spaces count: len("hi there") → 8
  • Empty string: len("") → 0
  • Useful for checking minimum/maximum lengths

Code examples

String length
python
name = input("Username: ")
if len(name) < 3:
    print("Too short — at least 3 characters")
else:
    print("Welcome, " + name)