Python: working with strings

Names, messages and passwords are all strings: text in a program. Python has lots of tools for measuring, cutting up and joining strings.

Practise this lesson free (7 questions)

Length and indexing

word = "computer"
print(len(word))
print(word[0])
print(word[-1])
Output:
8
c
r
len counts the characters. Each character has an index, starting at 0.
A negative index counts from the end: word[-1] is the last character.

Slicing and changing case

word = "computer"
print(word[0:3])
print(word.upper())
Output:
com
COMPUTER
word[0:3] is a slice: it starts at index 0 and stops before index 3.
.upper() makes capitals and .lower() makes small letters. The original string is not changed.

Joining strings

Concatenation joins strings with +:
first = "Ada"
last = "Lovelace"
print(first + " " + last)
prints Ada Lovelace.
You cannot join a string and a number directly. Convert the number with str() first:
age = 13
print("I am " + str(age))
prints I am 13.
A for loop can visit each character in turn: for letter in name:
Worked example

What does this print?
code = "PYTHON"
print(code[2:5])
print(len(code))

  1. Indexes: P=0, Y=1, T=2, H=3, O=4, N=5.
  2. code[2:5] takes indexes 2, 3 and 4: THO.
  3. len counts 6 characters.

Answer: THO then 6

Key idea

len() counts characters, indexes start at 0, a slice [a:b] stops before b, + joins strings and str() turns a number into a string so it can be joined.

Key words
AND
A Boolean operator that gives True (1) only when both inputs are True.
Program
A set of instructions written in a programming language that a computer can run.
String
A data type for text, written in quotation marks, such as "hello".
Output
Information sent out from a computer, for example to a screen, speaker or printer.
NOT
A Boolean operator that flips its input: True becomes False and False becomes True.
For loop
A count-controlled loop that repeats a set number of times.

All KS3 Computing key terms and definitions →

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 this print?
    print(len("Good morning"))

    Show the answer

    Answer: 12

    "Good morning" has 11 letters plus 1 space: 12.

  2. What does this print?
    animal = "tiger"
    print(animal[1])

    Show the answer

    Answer: i

    Index 0 is t, index 1 is i.

Check you have got it

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

Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.

Related lessons