Operators
11. Operators
Operators are symbols used to perform operations with numbers and variables.
Arithmetic operators
| Operator | Meaning | Example | Result |
|---|---|---|---|
+ | Addition | 5 + 2 | 7 |
- | Subtraction | 5 - 2 | 3 |
* | Multiplication | 5 * 2 | 10 |
/ | Division | 10 / 2 | 5.0 |
// | Floor division | 10 // 3 | 3 |
% | Remainder | 10 % 3 | 1 |
** | Power | 2 ** 3 | 8 |
Example:
a = 10
b = 3
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a % b)Comparison operators
These operators compare two values and return True or False.
| Operator | Meaning |
|---|---|
== | Equal to |
!= | Not equal to |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
Example:
speed = 80
print(speed > 50)
print(speed == 80)
print(speed < 100) 