# Python Operators

By using operators we can update or compare values or identities of variables.
OperationOperator SampleOutput
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

## Assignment Operators

We can assign or update value of a variable by using assignment operators
 Operator Syntax Equivalent Sample Output = x=5 x=5 x=5print(x) 5 += x += 5 x = x + 5 x=4 x += 5print(x) 9 -= x -= 5 x = x - 5 x=4 x -= 5print(x) -1 *= x *= 5 x = x * 5 x=4 x *= 5print(x) 20 /= x /= 5 x = x / 5 x=4 x /= 5print(x) 0.8 %= x %= 5 x = x % 5 x=29 x %= 5print(x) 4 //= x //= 5 x = x // 5 x=29 x //= 5print(x) 5 **= x **= 3 x = x ** 3 x=5 x **= 3print(x) 125 Read more on Bitwise operators to understand the codes below &= x &= 5 x = x & 5 x=68 x &=5print(x) 4 |= x |= 5 x = x | 5 x=68 x |=5print(x) 69 ^= x ^= 5 x = x ^ 5 x=68 x ^=5print(x) 65 >>= x >>= 5 x = x >> 5 x=68 x >>= 5print(x) 2 <<= x <<= 5 x = x << 5 x=68 x <<= 5print(x) 2

## Comparison Operators

We can compare two variable values by using comparison operators. Output of these comparison operator is always Boolean ( True or False )
OperationOperator SampleOutput
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

## Logical Operators

OperatorDescription SampleOutput
andTrue if both left and right side are Truea=5
b=15
print(a>10 and b<25)
False
orTrue if any one of left or right side are Truea=5
b=15
print(a>10 or b<25)
True
notReverse the output.
True if output is False , vice versa
a=5
print( not(a>10))
True

## Bitwise Operators

Subscribe to our YouTube Channel here

## Subscribe

* indicates required
Subscribe to plus2net

plus2net.com