2A.01 – Variables


Previous: Section 1 Summary Questions

Variables are named references to locations in memory for temporarily storing data while a program is running.

Each variable or constant should have a meaningful and unique identifier (name).

Identifiers can't be reserved keywords (like if, and or while) or start with numbers.

A constant is a special type of variable whose value does not change as the program runs.

Constant identifiers are usually written in CAPITALS.

Declaring a variable means setting its value for the first time.

In pseudo-code, we use code like num ← 123 to declare or change the value of a variable.

In Python, we use code like num = 123 to declare or change the value of a variable.



Which is a better identifier: number or n?

Tap/click to reveal number is more meaningful than n, and so would be preferred.





Next: 2A.02 - Data Types



© Rujul Nayak 2024-