In Python 2.5, Guido van Rossum added conditional expression. In Python there is no ternary conditional operator but by using Conditional Expression we can work like a Conditional Operator
a if <condition> else b
Above syntax first evaluates condition, If the condition will be true then A will be the result otherwise b will be the result.
a = int(input("Enter First Number : ")) b = int(input("Enter Second Number : ")) c = a if (a > b) else b print("Greatest Number is : ",c)
This is the Conditional Expression, This is not a statement. So You can’t assign the variable through expression and also can’t use pass as well as any other statements. Example is as follows:
pass if (a>b) else b = 3 #This operation you can't perform with conditional expression