Manipulating strings

Usernames, passwords and messages are all strings. Python gives you tools to measure, slice and change them.

Practise this lesson free (6 questions)

More tools

Length and position

len(word) gives the number of characters.
Characters are numbered from 0. If word = "Python", word[0] is "P" and word[5] is "n".
word[-1] is the last character.
word.find("h") gives the position of the first "h": 3. It gives -1 if not found.

Substrings (slicing)

word[start:end] gives the characters from start up to, but not including, end.
"Python"[0:3] is "Pyt". "Python"[2:] is "thon".

Case conversion and joining

word.upper() gives "PYTHON". word.lower() gives "python".
Compare in one case so "YES", "Yes" and "yes" are all accepted: if answer.lower() == "yes":
Join strings with +: "Py" + "thon" gives "Python".
Worked example

Make a username from the first 3 letters of "Amelia" and her birth year 2010.

  1. "Amelia"[0:3] = "Ame"
  2. str(2010) = "2010"
  3. Join with +

Answer: Ame2010

Key idea

len() counts characters. Positions start at 0. word[a:b] gives a substring up to but not including b. upper() and lower() change case; + joins strings.

Common mistakes
Quick check

Try two quick questions

See if it has sunk in. Answers are marked straight away.

Extra practice

2 more questions

Try each one, then tap to check.

  1. What does len("Algorithm") return?

    Show the answer

    Answer: 9

    A-l-g-o-r-i-t-h-m has 9 characters.

  2. word = "Server". What is word[0]?

    Show the answer

    Answer: S

    Indexes start at 0, so word[0] is the first character, S.

Check you have got it

Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.

Video for this lesson coming soon. Subscribe on YouTube

Sources and references

Facts checked against the sources below, 17 October 2026. Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.

What do exam command words like explain and evaluate mean? β†’

Related lessons