The ternary operator is a way of writing conditional statements in Python. As the name ternary suggests, this Python operator consists of three operands.
Let's suppose that we have the following code:
course = 'python'
a = 'enrolled in python course'
b = 'enrolled in other course'
So, the next code:
if course == 'python':
print(a)
else:
print(b)
will be equivalent to the following one:
print(a) if course == 'python' else print(b)