Python Operators
In Python, operators are special symbols used to perform operations on variables and values. Python supports a wide range of operators categorized based on their functionality.
Used to perform basic mathematical operations:
| Operator | Description | Example | Result |
|---|---|---|---|
+ | Addition | 10 + 5 | 15 |
- | Subtraction | 10 - 5 | 5 |
* | Multiplication | 10 * 5 | 50 |
/ | Division | 10 / 5 | 2.0 |
// | Floor Division | 10 // 3 | 3 |
% | Modulus (remainder) | 10 % 3 | 1 |
** | Exponentiation | 2 ** 3 | 8 |
Comparison Operatorsβ
Used to compare two values and return a Boolean result (True or False).
| Operator | Description | Example | Result |
|---|---|---|---|
== | Equal to | 5 == 5 | True |
!= | Not equal to | 5 != 3 | True |
> | Greater than | 5 > 3 | True |
< | Less than | 5 < 3 | False |
>= | Greater than or equal | 5 >= 5 | True |
<= | Less than or equal | 5 <= 3 | False |
Logical Operatorsβ
Used to combine conditional statements here.
| Operator | Description | Example | Result |
|---|---|---|---|
and | True if both operands are true | True and False | False |
or | True if at least one is true | True or False | True |
not | Reverses the result | not True | False |