AQA · GCSE · Computer Science
Course version: 8525 · Version from Sept 2020
String handling operations in a programming language: string to integer
Converting a string to an integer takes text that represents a whole number and turns it into an integer value the program can calculate with.
Checked against the AQA 8525 specification (opens in a new tab) on .
- Point 8 of 11
Study notes
From the checked teaching notes for this specification point.
The idea
Converting a string to an integer takes text that represents a whole number and turns it into an integer value the program can calculate with. For example, int("27") in Python produces the integer 27, which can then be added, subtracted or compared numerically. This matters because input read from a user is usually text, so a program must convert it before doing arithmetic. Learners should recognise when this conversion is needed, predict the resulting type, and understand that the text must contain valid digits; text such as "hello" cannot be converted to an integer and would cause an error.
What earns the marks
- Identifies that converting a string to an integer produces a whole-number value that can be used in arithmetic.
- Recognises that user input is typically text and must be converted before numeric calculation.
- Predicts the data type produced, namely an integer rather than a string.
- Explains that the string must contain valid digit characters, otherwise the conversion fails with an error.
- Distinguishes string-to-integer conversion from string-to-real conversion for decimal values.
Common mistakes and how to put them right
Adding digit text directly without conversion.
Put it right: Is that the text must first be converted to an integer so arithmetic is performed on numbers.
Expecting non-numeric text to convert successfully.
Put it right: Is that only valid digit strings convert, and invalid text raises an error.
Confusing integer conversion with real conversion.
Put it right: Is that integers are whole numbers while reals allow decimal parts.
Exam tips
- Identify whether the value needs to be a whole number or may include decimals before choosing integer or real conversion.
- Remember that input is usually text, so convert before any arithmetic.
- Check that the string contains only valid digits when predicting whether a conversion succeeds.
Try the lesson
The start of the String handling operations in a programming language: string to integer lesson, made from checked teaching notes for this specification point.
Have a go first
A variable holds the text "58". Which conversion changes this value into the whole number 58?
There is more to this lesson
The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge
Test your understanding of String handling operations in a programming language: string to integer
Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge