SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
Edexcel 1CP2 · Topic 2 · 2.2a

Variables, Constants
& Data Types

Integer · Float · String · Boolean · Char · Casting · Type Checking

CSZoneEdexcel GCSE Computer Science 1CP2
Variables and Constants

Named Storage Locations

Variable: a named location in memory that stores a value which can change during the program.
Constant: a named location that stores a value which does NOT change. Defined once; improves readability and maintainability.
score = 0 # variable
MAX_SCORE = 100 # constant (by convention: UPPERCASE)
score = score + 10
print(score) # 10
Data Types

The Five Key Types

TypeDescriptionExample
IntegerWhole number, positive or negative42, -7, 0
FloatReal number with decimal point3.14, -0.5
StringSequence of characters"Hello", "42"
BooleanTrue or False onlyTrue, False
CharSingle character'A', '9'
Type Casting

Converting Between Data Types

age = input("Enter age: ") # input() returns STRING
age = int(age) # cast to integer

price = 9.99
print(str(price)) # cast to string: "9.99"

print(float("3.14")) # string → float: 3.14
print(int(7.9)) # float → int: 7 (truncates)
Common mistake:Forgetting to cast input() to int or float before doing arithmetic — causes a TypeError
Exam Practice

Have a go at this question

Edexcel-style question
State an appropriate data type for each of the following: (a) a person's age, (b) whether a door is open, (c) a person's surname.
3 marks
(a) Integer — age is a whole number [1]
(b) Boolean — the door is either open (True) or closed (False) [1]
(c) String — a surname is text made of characters [1]
Key Takeaways

What to Remember

Variable: can change; Constant: cannot change after assignment
Types: Integer, Float, String, Boolean, Char
input() always returns a string — cast with int() or float() for arithmetic
Type casting: int(), float(), str(), bool() — convert between types