Python Operators
Mathematical Operators
| Operator | Description | Example |
|---|---|---|
| + | Addition | 3 + 2 → 5 |
| - | Subtraction | 3 - 2 → 1 |
| * | Multiplication | 3 * 2 → 6 |
| / | Division | 3 / 2 → 1.5 |
| // | Floor Division | 3 // 2 → 1 |
| % | Modulus (Remainder) | 3 % 2 → 1 |
| ** | Exponentiation (Power and Root) |
3 ** 2 → 9 |
Comparison Operators
| Operator | Description | Example |
|---|---|---|
| == | Equal to | 2 == 2 → true |
| != | Not equal to | 2 != 3 → true |
| < | Less than | 2 < 3 → true |
| > | Greater than | 2 > 3 → false |
| <= | Less than or equal to | 2 <= 3 → true |
| >= | Greater than or equal to | 2 >= 3 → false |
Boolean Operators
| Operator | Description |
|---|---|
| and | True if both operands are true; otherwise false. |
| or | True if at least one operand is true; otherwise false. |
| not | True if the operand is false; otherwise false. |
Bitwise Operators
| Operator | Description |
|---|---|
| x << n | Shift bits of x left by n positions |
| x >> n | Shift bits of x right by n positions |
| x & y | Bitwise AND of x and y |
| x | y | Bitwise OR of x and y |
| x ^ y | Bitwise XOR of x and y |
| ~x | Bitwise NOT of x |
