SSkilvy

First building blocks: variables and types

Let us start with the most basic. A variable is a name behind which a value is stored. Like a labeled box you can put data into and take out by name. This is the foundation of any code.

DataVariable = nameUse in code Variables Store values
Variables store data; data has types: numbers, strings, booleans.

Variables

name = "Anna"
age = 30
price = 19.99

Here name, age, price are variables. The = sign assigns a value to a name. Then you can use the variable instead of the value: age returns 30.

Main data types

  • Integers (int): age = 30
  • Floats (float): price = 19.99
  • Strings (str): text in quotes, name = "Anna"
  • Booleans (bool): True or False — yes/no.

Output: print

print("Hello!")
print(name)
print("Age:", age)

print() outputs a value to the screen — so you see the result of the code. This is your main tool to check what is happening.

Write a simple example with variables and print, explain it line by line.
Example — compute the cost of a purchase:\n\n```python\nprice = 100 # price of one item (a number)\nquantity = 3 # quantity (a number)\ntotal = price * quantity # compute the sum, * is multiplication\nprint("Total:", total) # output the result\n```\n\nLine by line: 1) `price = 100` — create the variable price with value 100. 2) `quantity = 3` — the quantity variable. 3) `total = price * quantity` — compute and store the result (100 x 3 = 300) in a new variable total. 4) `print("Total:", total)` — output the text "Total:" and the value of total. On screen: `Total: 300`. The `#` sign starts a comment — text for a human that Python ignores. Try changing the numbers and running it — you will see how the result changes. That is how you learn: change the code, see what comes out.

Experiment

The best way to understand is to try yourself. Change variable values, print them, combine them. Errors are normal and part of learning: Python will tell you what is wrong. Write small pieces of code and run them to see the result right away.

Rule: a variable is a name for storing a value. Types: numbers (int, float), strings (str), booleans (bool). print() outputs the result. Learn by changing code and running it.

🧠 What is a variable in Python?