Logical Operators: ================== -> three types: 1) Logical and ==> and 2) Logica or ==> or 3) Logical not ==> not -> Logical values ==> Boolean values True, False Logical Operators with Boolean values: ====================================== 1) Logical and: =============== -> Binary operator a b a and b ======================= True True True True False False False True False False False False -> Logical and describes that: when both inputs are "True", output ==> True when any input is "False", output ==> False Logical Or ========== -> Binary operator a b a or b ======================= True True True True False True False True True False False False -> Logical or describes that: when any input is "True", output ==> "True" if both inputs are "False", output ==> "False" Logical not: ============ -> Unary Operator Negate the input a not a ============= True False False True Logical Operators can define with other than Boolean values: ============================================================ Logical and: ============ 1) If the first operand (input-1) is non-zero value, output: "second operand value (input-2)". Ex: 9 and 0 ==> 0 -9 and 7 ==> 7 7 and -9 ==> -9 print(9 and 0) print(-9 and 7) print(7 and -9) 2) If the first operand (input-1) is zero, output : 0 print(0 and -1) print(0 and 7) print(0 and 123) Logical or: =========== 1) When the First input (input-1) is zero, output : second operand value (input-2) print(0 or -1) print(0 or 9) 2) When the first input (input-1) is non-zero value, output : first operand value (input1). print(12 or 10) print(-12 or -10) print(-12 or 0) Logical not: =========== 1) any non-zero value consider as "True" and zero ==> False by the python. 2) when we can define logical not to non-zero value, output ==> False 3) when we can define logical not to zero, output ==> True print(not -10) print(not 0) ================================================== Conditional Operator: ===================== -> also called as "Ternary Operator". Syntax: variable = Expression-1 if test-condition else Expression-2 -> If the test-condition is evaluated as "True", then: Expression-1 can execute and assign its value to that resultant variable. -> If the test-condition is evaluated as "False", then: Expression-2 can execute and assign its value to that resultant variable. # WAP TO FIND THE NUMBER IS POSITIVE OR NEGATIVE. n = int(input("Enter some integer:")) result = "n is positive number" if n > 0 else "n is negative number" print(result) Identity Operators: =================== -> two types: 1) is 2) is not -> Can use to check whether the two data objects are pointing to the same address location or not. -> return: Boolean value a = 10 b = 20 c = 10 print("Address of a = ",id(a)) print("Address of b = ",id(b)) print("Address of c = ",id(c)) print(a is b) # a and b are pointing to the same address False print(a is c) # a and c are with same addresses True print(a is not b) # True print(a is not c) # False Membership Operators: ==================== -> two types: 1) in 2) not in -> return: Boolean values a = "Python is Scripting Language" # b = 103 print('Scripting' in a) # True print('Scripting' not in a) # False # print(1 in b)