Operation | Operator | Sample | Output |
---|---|---|---|
Addition | + | a=4 b=5 print(a+b) | 9 |
Subtraction | - | print(a-b) | -1 |
Multiplication | * | print(a*b) | 20 |
Division | / | print(a/b) | 0.8 |
Modulus | % | a=40 b=9 print(a%b) | 4 |
Exponentiation | ** | a=3 b=4 print(a**b) | 81 |
Floor division | // | a=29 b=5 print(a//b) | 5 |
Operator | Syntax | Equivalent | Sample | Output |
= | x=5 | x=5 | x=5 print(x) | 5 |
+= | x += 5 | x = x + 5 | x=4 x += 5 print(x) | 9 |
-= | x -= 5 | x = x - 5 | x=4 x -= 5 print(x) | -1 |
*= | x *= 5 | x = x * 5 | x=4 x *= 5 print(x) | 20 |
/= | x /= 5 | x = x / 5 | x=4 x /= 5 print(x) | 0.8 |
%= | x %= 5 | x = x % 5 | x=29 x %= 5 print(x) | 4 |
//= | x //= 5 | x = x // 5 | x=29 x //= 5 print(x) | 5 |
**= | x **= 3 | x = x ** 3 | x=5 x **= 3 print(x) | 125 |
Read more on Bitwise operators to understand the codes below | ||||
&= | x &= 5 | x = x & 5 | x=68 x &=5 print(x) | 4 |
|= | x |= 5 | x = x | 5 | x=68 x |=5 print(x) | 69 |
^= | x ^= 5 | x = x ^ 5 | x=68 x ^=5 print(x) | 65 |
>>= | x >>= 5 | x = x >> 5 | x=68 x >>= 5 print(x) | 2 |
<<= | x <<= 5 | x = x << 5 | x=68 x <<= 5 print(x) | 2 |
Operation | Operator | Sample | Output |
---|---|---|---|
Equal | == | a=4 b=5 print(a == b) | False |
Not Equal | != | a=4 b=5 print(a != b) | True |
Greater than | > | a=4 b=5 print(a > b) | False |
Less than | < | a=4 b=5 print(a < b) | True |
Greater than or equal to | >= | a=4 b=5 print(a>=b) | False |
Less than or equal to | <= | a=4 b=5 print(a<=b) | True |
Operator | Description | Sample | Output |
---|---|---|---|
and | True if both left and right side are True | a=5 b=15 print(a>10 and b<25) | False |
or | True if any one of left or right side are True | a=5 b=15 print(a>10 or b<25) | True |
not | Reverse the output. True if output is False , vice versa | a=5 print( not(a>10)) | True |