GCSE · Computer Science · AQA · Spec 8525
Integer / real to string conversion
In Python, "Score: " + 2048 stops your program dead. The number has to become text first — and exactly when you convert it changes the answer.
Python · watch the types
Same digits, new job
Step through the program. Next to every value is its data type — keep your eye on that, not just the digits.
Before you press Next: the digits of score never change in this program. So what does?
1 score = 20482 time = 12.53 score_text = str(score)4 time_text = str(time)5 message = "Score " + score_text + " in " + time_text + " seconds"6 print(message)7 digits = len(score_text)8 print(digits)
Variables
Output
Step 1: score holds a whole number, so its type is integer. It can do maths: score + 1 would give 2049.
Press Next and watch the type after each value. The digits stay put; the type is what changes.
Predict, then check
Two lines, same numbers, same str(). The only difference is the moment the conversion happens.
Line A, print("Total: " + str(3 + 4)), prints Total: 7. What does line B, print("Total: " + str(3) + str(4)), print?
Your call
Convert it, or leave it?
Put each job in the right column.
Still to sort
Convert to a string first (0)
The number has to behave like text: joined into a message, or treated as characters.
Where the line is: It's the JOB that decides, not how the number looks. Text jobs need a string.
Use the number as it is (0)
The job is maths, or comparing sizes.
Where the line is: Arithmetic and comparisons need a number. Turning it into text first would stop them working.
Each card is a job a program needs to do with a number. Decide before you read why.
In AQA pseudo-code the two operations are written IntToString(…) and RealToString(…), and the message is displayed with OUTPUT.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
What you need to know
- A string conversion operation turns a value into a string. Integer to string: 42 becomes "42". Real to string: 12.5 becomes "12.5".
- The digits stay the same; the type changes. A string is text, so you can join it to other text and count its characters, but you can't do arithmetic with it.
- Convert a number when it has to be joined into text, or when you need its digits as characters.
- In Python, str() does both conversions. Python won't join a string to a number, so "Score: " + 10 stops the program with a TypeError.
- Conversion makes a new value. The original variable is still a number.
The big picture
Converting a number to a string keeps its digits but changes its type — and the type decides what you can do with it. Integer to string turns 42 into "42"; real to string turns 12.5 into "12.5", with the decimal point as one of the characters. You convert when a number has to join other text, or when you want to work with its digits as characters, such as counting them. Once values are strings, + joins them instead of adding, so do any maths first and convert the answer. In Python, str() does both conversions.
Key points
Worked example
Problem
A shop program stores quantity = 3 (an integer) and price = 1.25 (a real). Write one line of Python that prints the message: You owe 3.75 for 3 items
⚠ Watch out
Joining a number straight onto text, such as print("Lives: " + lives). In Python that stops the program with a TypeError. Convert it first: print("Lives: " + str(lives)).
Memory hook
Same digits, new job. Numbers do maths; strings do sentences. Convert at the moment the number joins the sentence — after the maths is done.
Check yourself
Without looking back: if n = 305, what is str(n)? What is len(str(n))? And after those lines have run, what type is n?
Flashcards
(9)What does integer-to-string conversion do?
What does real-to-string conversion do?
Which Python function converts an integer or a real to a string?
Give two reasons to convert a number to a string.
What does + do with two numbers, and with two strings?
What happens in Python if you run "Score: " + 10?
After s = str(n), what type is n?
Can you do arithmetic with the string "12.5"?
Why must you convert before using len() to count a number's digits?
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 postedMore AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)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 30 September 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.