Course Content
How to Add a Virtual Environment in Python
0/1
Set
0/1
Python
About Lesson

The ternary operator in Python, often referred to as the conditional expression, enables you to assess a condition and produce one of two values depending on whether the condition is True or False. It uses the following syntax:

Python
 expr1 if condition else expr2

Example

Python
#biggest between 2 nos using ternery operator

a=int(input("enter 1st number"))
b=int(input("enter 2nd number"))

c=a if a>b else b  # in C a>b?a:b;

print("Biggest Number is ",c)

print("A is Biggest") if a>b else print("B is Biggest")
# in C a>b?printf("A is Big"):print("B is Big")