How can the ternary operators be used in python?

Last updated:9/18/2020 10:22:21 PM

1 Answers

Prakash nidhi Verma
Prakash nidhi Verma

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. 

Syntax:  The Ternary operator will be given as: 


if [expression]
else [on_false]
x, y = 25, 50
big = x
if x < y
else y


The expression gets evaluated like if x<y else y, in this case if x<y is true then the value is returned as big=x  if it is incorrect then big=y will be sent as a result.