Ternary or Conditional Operator in Python

Consider a following piece of code in python:


age = 22

if age>=18:
    print('You can vote.')
else:
    print('You can not vote.')

Above code can be written in one line using ternary or conditional operator, which looks like:


age = 22
print('You can vote.') if age>=18 else print('You can not vote.')

This structure i.e. <statement> if condition else <statement> in python is known as Ternary Operator.