Coding for All
Lesson 3: Numbers
Numbers Store numbers and add them together.
1apples = 3
2bananas = 5
3print(apples + bananas)
Terminal
$ python3 main.py
8
Every line, explained
apples = 3
This creates a variable: a named box that stores a value. In Python you just write name = value: the = stores the value on the right into the name on the left. No special type word, no semicolon; Python keeps it simple. Numbers don't need quotes: 3 is a number you can do maths with, while "3" would be text.
bananas = 5
This creates a variable: a named box that stores a value. In Python you just write name = value: the = stores the value on the right into the name on the left. No special type word, no semicolon; Python keeps it simple.
print(apples + bananas)
print(...) shows whatever is inside its round brackets in the terminal, then moves to a new line. It is written all in lowercase, and it needs both brackets. Python works out apples + bananas first (3 + 5 = 8), then prints the answer.