Skip to content

Variables ​

What Is a Variable? ​

Definition: A variable is like a "box" that stores data. It is used to reuse and manage values in a program.

Why use variables?

  • You don't need to type the same data over and over
  • Code becomes more readable and easier to maintain
  • Programs become more flexible

Variable declaration example

python
name = "Jo"        # store "Jo" in the variable name
age = 25           # store 25 in the variable age
score = 95.5       # store 95.5 in the variable score

print(name)        # output: Jo
print(age + 5)     # output: 30 (reusing the variable)

Data Types at a Glance ​

Featureintstrboollistdict
Written as123"abc"True/False[1, 2, 3]{"key": "value"}
OrderedXOXO△
MutableXXXOO
IndexingXOXOX (access by key)
Used forNumber calculationsTextTrue/falseStoring multiple valuesPairing information

Summary ​

ConceptSummary
VariableA box that stores data → to reuse values
int · str · bool · list · dictPython's basic data types (explained one by one in the next articles in this category)

References ​

Reference: personal Notion study notes (onboarding course)