Professional Documents
Culture Documents
In python we can chain relational operators along with var/exp./literals. But the logical expression
implicitly implement ‘and’ operation.
Example:-
(1)
a,b,c=15,12,10
b<a>c
will return True(explanation:- b<a and b>c)
(ii)
a,b,c = 10,10,10
a==b==c
Will return True.
Conditional Operator
ReturnValueIfTrue will be returned if the condition returns True otherwise it will return
ReturnValueIfFalse.
bitwise operators
Operates on Bits.
(i) & - Bitwise and operator. This operator operates on two bits. If both bits are 1 then it returns 1
otherwise it will return 0
Example:-
a=10 # its’ binary equiv. Is 1010
a & 7 #7’s binary equiv. Is 111
It will return 2
(I will discuss later regarding number system)
1 & 0 ->0
0 & 1 ->0
0 & 0 ->0
1 & 1 ->1
(ii) | - Bitwise OR operator. This operator operates on two bits. If any one of them is 1 then it
returns 1
Ex:-
a=10
a|7
will return 15
(iii) ^ (XOR) – It will return 0 when two bits are On(1). In all othercases sames as or gate.
Example:
15 ^ 7
will return 8