GCSE · Computer Science · OCR · Spec J277

Data type: Character and string

Type 5, then 5, into a program that adds two numbers. It prints 55. Nothing is broken: Python did exactly what you told it. So what did you tell it?

Computer Science · Data types

Two fives make fifty-five

Six lines of Python. The user types 5, then 5. Step through and keep your eye on the trace table: the quotes tell you what each value really is.

Before you press Next: the user types 5, then 5. What do you think the last line prints?

1 x = 5 + 5
2 print(x)
3 a = input("First number: ")
4 b = input("Second number: ")
5 total = a + b
6 print(total)
xabtotal
10

Output

 

Step 1: No quotes anywhere: 5 and 5 are numbers here, so + adds them. x holds 10. No surprises yet.

1 / 6

Quotes in the trace table mean the value is stored as a string (text). No quotes means a number.

Step 1 of 6: No quotes anywhere: 5 and 5 are numbers here, so + adds them. x holds 10. No surprises yet..

Watch out: print shows a string without its quotes, so 55 on the screen looks exactly like a number. The trace table is where the quotes give it away.

Computer Science · Data types

Char, string or not text at all?

Pick a value, then choose where it belongs.

Still to sort

Char: a single character (0)

Exactly one character inside the quotes. A letter, a digit, a symbol and even a space all count.

Where the line is: A char is really a string that is just one character long. So "a" is a char, but "ab" is a string.

String: text of several characters (0)

Text in quotes. Letters, digits, spaces and symbols are all allowed.

Where the line is: Digits in quotes are still text. "2026" is a string, not a number.

Not text: a number (0)

No quotes. Python treats it as a number, so + would add it.

8 of 8 still to sort.

Eight values. Count what's inside the quotes, and check whether there are quotes at all.

Computer Science · input

So what did input really store?

A program runs age = input("How old are you? ") and the user types 14.

Which is closest to what you think is stored in age?
How sure are you?

Predict, then check

Look at exactly what's inside the quotes, spaces included.

first = "Priya" and last = "Shah". What does print(first + last) show?

Computer Science · Converting with str

Find the line that crashes

This program should print a message like Well done Sam! You scored 42. Instead it stops with an error. Which line is the problem?

A student's program — which line goes wrong?

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

Type a number into a program and it feels like a number. To Python it might just be text. By the end you'll know why, and how to stay in control of it.

What you need to know

  • Python uses data types to store and process information correctly.
  • A string holds data as text. You write it inside quotes, like "hello".
  • Strings aren't just letters: they can hold numbers, characters and symbols. "£4.99" is text.
  • Char is short for character. A char is a single string character, such as "a".
  • Have a goYour mate insists "ok" must be a char, because it's such a tiny word. Do you agree?

    No. "ok" is a string.

    A char is one single character, and "ok" has two. Being short doesn't make something a char; only having exactly one character does.

  • input always returns a string, even when the user types a number.
  • Add two strings with + and they're concatenated, which means joined together end to end.
  • Have a goPredict: what does "10" + "1" give?

    "101"

    Both values are strings, so + joins them end to end. It doesn't add them to make 11: that only happens with numbers.

  • Concatenation adds nothing extra, not even a space. If you want a space, join one in.
  • The str function converts a value to a string: str(42) gives "42".
  • Have a goTry it in your head: what does str(3) + "D" give?

    "3D"

    str turns the number 3 into the string "3", then + joins the two strings. Without str, Python would refuse to join the number to the text.

  • Python won't join a number straight onto a string with +. Convert the number with str first.

The big picture

Python uses data types to store and process information correctly. A string holds data as text, written in quotes, and it can hold numbers, characters and symbols as well as letters. A char (short for character) is a single string character, such as "a". The input function always returns a string, even when the user types a number. Adding two strings with + concatenates them: it joins them end to end, so "5" + "5" gives "55". The str function converts a value to a string, which is how you join a number onto a message.

Key points

1Data types let Python store and process information correctly; the type decides what + does.
2A string is text in quotes and can hold numbers, characters and symbols.
3A char (character) is a single string character, such as "a".
4input returns a string, even when a number is entered.
5+ on two strings concatenates (joins) them; str converts a value to a string so it can be joined.

Worked example

Problem

A program runs these three lines, and the user types 2026: year = input("Year: ") age = 15 print("In " + year + " I am " + str(age)) What data type is each value, and exactly what does the last line print?

⚠ Watch out

Treating a typed number as a number. input returns a string, so if a program reads 3 and 4 with input and adds them with +, it concatenates them and gets "34", not 7.

🧠

Memory hook

Quotes mean text. Two fives make fifty-five when they're strings.

✓

Check yourself

Cover the page. Explain why "9" is a char but "99" is not. Then say what "9" + "9" gives, and what str(9) gives.

Flashcards

(10)
Why does Python use data types?
To store and process information correctly. The data type decides what Python can do with a value, such as what + does.
What is a string?
Data held as text, written in quotes. It can hold numbers, characters and symbols as well as letters.
What does char stand for, and what is it?
Character. A char is a single string character, for example "a".
Is "2026" a number or a string?
A string. The quotes make it text, even though every character is a digit.
What data type does input return when the user types a number?
A string. input returns the data as a string even if a number is entered.
What does concatenate mean?
Join strings together end to end. In Python, + concatenates two string values.
Does concatenation add a space between the strings?
No. It joins them exactly as they are, so you join in a space (" ") yourself if you need one.
Which function converts a value to a string?
str. For example, str(8) gives "8".
Why does "Age: " + 15 cause an error, and how do you fix it?
+ can't join a string to a number. Convert the number first: "Age: " + str(15).
Is a space a character?
Yes. " " is a single character in quotes, so it is a char.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More OCR GCSE Computer Science topics

See the full OCR Computer Science curriculum →

How this lesson was checked. This OCR GCSE Computer Science (specification J277)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 3 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.