The Ternary operator is the operator that is used to show the conditional statements. This consists of the true or false values with a statement that has to be evaluated for it.
Ternary operator in python is like a plain English. For instances, display a value if a less than b else display b value. See example below.
# Program to demonstrate conditional operator x, y = 49, 69 # Assign value of x in minValue if x < y else Assign y minValue = x if x < y else y print(minValue)
# Python program with nested ternary operator x, y = 10, 20 if x != y: if x > y: print("x is greater than y") else: print("y is greater than x") else: print("Both x and y are equal")
Categories: Cyber Security