Variables and Constants
A variable is a named location in the computer's memory that stores one value which can change while the program runs. For example, age may hold 15 and later be changed to 16.
In contrast, a constant stores one value that cannot change once set, for example PI = 3.142. Constants are useful for fixed values used repeatedly, making code clearer and easier to maintain.
Key idea
A variable stores a value that can change; a constant stores a fixed value that stays the same throughout the program.
Data Types
A data type determines what kind of value can be stored and what operations can be performed on it. The basic data types include:
- Integer — a whole number with no decimal part, for example 7, -20, 100.
- Float (real) — a number with a decimal point, for example 3.14, 98.6.
- String — a sequence of characters such as text, for example "Ali", "SPM 2025".
- Boolean — only two values, true or false.
Declaration and Assignment
Declaration is the act of giving a variable a name and stating its data type, for example age : integer. Assignment is the act of storing a value into a variable using the assignment operator, usually the = sign, for example age = 15.
Example
name = "Aminah" # string age = 16 # integer height = 1.62 # float passed = True # boolean
Remember
Choose the right data type: use integer for whole numbers, float for decimal values, string for text, and boolean for true/false conditions.