Ternary Operator in Python

Last updated 4 months, 2 weeks ago | 197 views 75     5

Tags:- Python

Python | Ternary Operator

python uses an if-else conditional statement in a single line to represent the Ternary Operator.

[true] if [expression] else [false]
 

Let's see an example of Ternary Operator

a, b = 10, 20
   
max = a if a > b else b 
  
print(max)

The above program is showing an example of finding the max number among two numbers using the Ternary operator.