Operators: ========== Logical Operators: ================== Logical or Operator: ==================== ==> keyword : or ==> binary operator a = True b = False print(a or a) print(a or b) print(b or a) print(b or b) print(a and a) print(a and b) # when the first input (left) is "True", output ==> "First Input" # non-zero ==> True print(10 or 20) # 10 print(20 or 10) # 20 # when the first input ==> 0 (False), output ==> "second input" print(0 or 10) # 10 print(-10 or 0) ================================ Note: ==== 1) when we have defined logical or and logical and operator with Boolean values: output ==> Boolean value 2) if we can define or/and operators with integer: output ==> integer 3) if input ==> float output ==> float etc. Logical not Operator: ===================== keyword: not ==> Input ==> True output ==> False ==> Input ==> False output ==> True a = True b = False print(not a) print(not b) c = 100 d = -100 e = 0 print(not c) print(not d) print(not e) Note: ==== for any kind of input: logical not operator's output ==> Boolean value. =============================================================== Bitwise Operators: ================== Note: ===== Bitwise Operations can allowed to define with: integer, Boolean and string also. But not with float and complex. Integer: decimal binary octal hexa-decimal ex: 10 ==> 0b1010 ==> there are list of bitwise operators: 1) bitwise and ==> & 2) bitwise or ==> | 3) bitwise xor ==> ^ 4) bitwise complement ==> ~ 5) left shift operator ==> << 6) right shift operator ==> >> 1) bitwise and ==> & ====================== ==> binary operator Syntax: input1 & input2 process: ========= 1) input1 ==> binary 2) input2 ==> binary 3) bitwise and operation can perform bit by bit from right to left direction. print(9 & 11) print(True & True) print(True & False) print(False & True) print(False & False) # print('a' & 'b') Type Error # print(1.2 & 2.1) # print(1-2j & 2-3j) =================================================== 2) Bitwise or Operator (|): =========================== ==> Binary Operator Syntax: input1 | input2 input1 ==> binary input2 ==> binary ==> from right to left bit by bit logical or truth table operation should define. print(23 | 97) print(True | True) print(True | False) print(False | True) print(False | False) =================================== 3) Bitwise Xor (^) =================== Syntax: input1 ^ input2 a = 7 b = 11 print(a ^ b) print(True ^ True) print(True ^ False) print(False ^ True) print(False ^ False) ============================================= 4) Bitwise Complement: ====================== ==> Symbol: ~ ==> Unary Operator Syntax: ~input Work: 1) input ==> binary 2) find the 2's complement of the given binary input print(~0) print(~1) print(~9) # ~0 ==> -1 # ~1 ==> -2 # ~9 ==> -10 # 2's complement(number) ==> -number - 1 ==> -(number + 1) # ~-10 ==> 10 -1 ==> 9 print(~-10)