Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.
Operators are symbols that do something with values: maths, comparison, or logic.
| Symbol | Meaning | Example |
|---|---|---|
+ |
Add | 5 + 3 → 8 |
- |
Subtract | 5 - 3 → 2 |
* |
Multiply | 5 * 3 → 15 |
/ |
Divide | 6 / 3 → 2.0 |
// |
Divide (whole number) | 7 // 2 → 3 |
% |
Remainder | 7 % 2 → 1 |
You can use variables too: score * 2, health - 1.
These compare two values and give True or False:
| Symbol | Meaning | Example |
|---|---|---|
== |
Equal to | 5 == 5 → True |
!= |
Not equal to | 5 != 3 → True |
< |
Less than | 3 < 5 → True |
> |
Greater than | 10 > 7 → True |
<= |
Less or equal | 4 <= 4 → True |
>= |
Greater or equal | 3 >= 3 → True |
Example:
score = 10
print(score > 5) # True
print(score == 10) # True
and — both sides must be True: (age >= 10) and (age < 20)or — at least one side True: (score == 0) or (lives == 0)not — flip True/False: not game_overAsk the user for two numbers (use int(input(...))). Then print:
Next: 2.1 Conditionals — making decisions with if and else.