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 = 2048
2 time = 12.5
3 score_text = str(score)
4 time_text = str(time)
5 print(score_text)
6 print(time_text)

Variables

score=2048 · integer

Output

 

Step 1: score holds a whole number, so its type is integer.

1 / 6

Press Next and watch the type after each value. The digits stay put; the type is what changes.

Step 1 of 6: score holds a whole number, so its type is integer..

Watch out: Look at the quote marks. 2048 is a number; "2048" is text made of the characters 2, 0, 4 and 8. They look almost the same on screen, but one is an integer and the other is a string.

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.

6 of 6 still to sort.

Each card is a value a program holds. Decide which string conversion it needs before you read why.

Find the bug

Which comment is wrong?

A student wrote this Python program and added a comment showing the string each line stores. One comment is wrong. Which line is to blame?

A program with one wrong comment — which line goes wrong?

Your turn to write it

Write it, then check it

answered holds 12, and avg_time holds 4.5. The strings are "12" and "4.5".

A quiz app stores how many questions a player answered in the integer variable answered, and their average time per question, in seconds, in the real variable avg_time. Using string conversion operations, write code (pseudo-code or a programming language you have studied) that converts each value to a string and outputs both strings. [3 marks]

0 words · your answer stays on this page and is not sent anywhere.

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

1Integer to string turns a whole number into text with the same digits: str(305) gives "305".
2Real to string turns a number with a decimal part into text: str(0.75) gives "0.75", with the 0 and the decimal point as characters.
3Quote marks show a string: 2048 is a number, "2048" is text.
4Converting keeps the digits and changes the type from a number to a string.
5Use integer to string for an integer and real to string for a real. In Python, str() does both.

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?
It turns a whole number into text made of the same characters: 42 becomes "42".
What does real-to-string conversion do?
It turns a number with a decimal part into text. The decimal point becomes one of the characters: 3.5 becomes "3.5".
Which Python function converts an integer or a real to a string?
str(). For example, str(42) gives "42" and str(3.5) gives "3.5".
When a number is converted to a string, what stays the same and what changes?
The digits you see stay the same. The type changes: a number becomes a string.
What shows that a value written in Python is a string?
Quote marks. 2048 is a number; "2048" is a string.
What string does real-to-string conversion give for 0.75?
"0.75". Every character comes along: the 0, the decimal point, the 7 and the 5.

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 AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

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.