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
| Feature | int | str | bool | list | dict |
|---|---|---|---|---|---|
| Written as | 123 | "abc" | True/False | [1, 2, 3] | {"key": "value"} |
| Ordered | X | O | X | O | △ |
| Mutable | X | X | X | O | O |
| Indexing | X | O | X | O | X (access by key) |
| Used for | Number calculations | Text | True/false | Storing multiple values | Pairing information |
Summary
| Concept | Summary |
|---|---|
| Variable | A box that stores data → to reuse values |
| int · str · bool · list · dict | Python's basic data types (explained one by one in the next articles in this category) |
References
Reference: personal Notion study notes (onboarding course)
