GCSE · Computer Science · AQA · Spec 8525
Integer / real to string conversion
The number 2048 and the text "2048" show the same digits on screen, yet they are different kinds of value. Converting turns one into the other.
Python · watch the types
Same digits, new type
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 print(score_text)6 print(time_text)
Variables
Output
Step 1: score holds a whole number, so its type is integer.
Press Next and watch the type after each value. The digits stay put; the type is what changes.
Predict, then check
Think about which characters make up 30.25. The decimal point counts as one.
In Python, str(30.25) converts a real to a string. What string does it give?
Your call
Which conversion?
Put each value in the conversion it needs.
Still to sort
Integer to string (0)
The value is a whole number.
Where the line is: It's the type of the value that decides: a whole number is an integer.
Real to string (0)
The value has a decimal part.
Where the line is: A number with a decimal part is a real, even when the digits after the point are small.
Each card is a value a program holds. Decide which string conversion it needs before you read why.
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: text made of characters.
- Integer to string turns a whole number into text: 42 becomes "42".
Have a goInteger to string on 305. Write down the exact string you get before you look.
"305"
Every digit comes along as a character, so the string is the same three characters. Writing 305 without quote marks forgets it's text now.
- Real to string turns a number with a decimal part into text: 12.5 becomes "12.5".
Have a goYour mate Sam says str(0.75) gives "75" because the dot isn't a digit. What do you tell Sam?
It gives "0.75".
Real to string keeps every character, and the 0 and the decimal point are characters too. Sam has dropped two of them.
- The decimal point is just another character, so real to string keeps it.
- The characters look the same as the number. What changes is the type: from a number to a string.
Have a goQuick check: which conversion operation does str(90210) perform, and what string does it give?
Integer to string, giving "90210".
90210 is a whole number, so it is an integer. Integer to string keeps the same five digits as characters.
- Use integer to string for a whole number and real to string for a number with a decimal part.
- In Python, str() does both conversions: str(42) gives "42" and str(12.5) gives "12.5".
The big picture
A string conversion operation turns a value into a string: text made of the characters you'd see on screen. Integer to string turns 42 into "42"; real to string turns 12.5 into "12.5", decimal point included. The digits stay the same and the type changes from a number to a string. In Python, str() does both conversions.
Key points
Worked example
Problem
A program stores age = 15 (an integer) and height = 1.62 (a real). Write Python that converts each value to a string and stores the results in age_text and height_text. State the value of each.
⚠ Watch out
Dropping a character when writing the converted value, such as writing "75" for the real 0.75. Real to string keeps every character, decimal point included, so the answer is "0.75".
Memory hook
Same digits, new type. Integer to string, real to string: the characters stay put, and the type changes.
Check yourself
Without looking back: if n = 305, what is str(n)? If r = 0.75, what is str(r)? And what type is each result?
Flashcards
(6)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?
When a number is converted to a string, what stays the same and what changes?
What shows that a value written in Python is a string?
What string does real-to-string conversion give for 0.75?
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
- Data validation routines
- Equal to (relational operator)
- Greater than (relational operator)
- Greater than or equal to (relational operator)
- Identifying and categorising errors
- Indefinite (condition-controlled) iteration
- Integer data type
- Integer division and remainder
- Iteration
- Keyboard input
- Less than (relational operator)
- Less than or equal to (relational operator)
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 26 October 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.