|
| 1 | +# Arithmetic Operators (+, -, *, /, %, **, //) |
| 2 | +a = 10 |
| 3 | +b = 3 |
| 4 | +print(a + b) # Output: 13 (Addition) |
| 5 | +print(a - b) # Output: 7 (Subtraction) |
| 6 | +print(a * b) # Output: 30 (Multiplication) |
| 7 | +print(a / b) # Output: 3.3333333333333335 (Division) |
| 8 | +print(a % b) # Output: 1 (Modulus - remainder after division) |
| 9 | +print(a ** b) # Output: 1000 (Exponentiation) |
| 10 | +print(a // b) # Output: 3 (Floor division - rounded down to the nearest whole number) |
| 11 | + |
| 12 | +# Assignment Operators (=, +=, -=, *=, /=, %=, **=, //=) |
| 13 | +x = 5 |
| 14 | +x += 3 # Equivalent to x = x + 3 |
| 15 | +print(x) # Output: 8 |
| 16 | + |
| 17 | +y = 10 |
| 18 | +y **= 2 # Equivalent to y = y ** 2 |
| 19 | +print(y) # Output: 100 |
| 20 | + |
| 21 | +# Comparison Operators (==, >=, <=, >, <, !=) |
| 22 | +m = 15 |
| 23 | +n = 20 |
| 24 | +print(m == n) # Output: False (Equal to) |
| 25 | +print(m >= n) # Output: False (Greater than or equal to) |
| 26 | +print(m <= n) # Output: True (Less than or equal to) |
| 27 | +print(m > n) # Output: False (Greater than) |
| 28 | +print(m < n) # Output: True (Less than) |
| 29 | +print(m != n) # Output: True (Not equal to) |
| 30 | + |
| 31 | +# Logical Operators (and, or, not) |
| 32 | +p = True |
| 33 | +q = False |
| 34 | +print(p and q) # Output: False (Logical AND) |
| 35 | +print(p or q) # Output: True (Logical OR) |
| 36 | +print(not p) # Output: False (Logical NOT) |
0 commit comments