1# Program to demonstrate conditional operator
2a, b = 10, 20
3# Copy value of a in min if a < b else copy b
4min = a if a < b else b
1is_fast = True
2car = "Ferrari" if is_fast else "Sedan"
3# with tuples (avoid):
4car = ("Sedan", "Ferrari")[is_fast]
5# ShortHand ternary
6msg = True or "Some" # True
7msg = False or "Some" # 'Some'
8output = None # -> False
9msg = output or "No data returned" # 'No data returned'
1a, b = 10, 20
2# Copy value of a in min if a < b else copy b
3min = a if a < b else b
1# Ternary expression syntax:
2# value_if_true if condition else value_if_false
3#
4# Example:
5a = True
6b = "yes" if a else "no" # b will be set to "yes"