short hand if else in Python

Given fig. show how short-hand if else statement works in python.
Python starts script execution from top and goes to end.
vale 5 is assigned to the variable a and 3 is assigned to b.
i.e.
a=5
b=3
then we have statement.
print(a," is Maximum") if a>b else print(b,"is maximum")
here the condition if a>b is true i.e. 5>3 is true.
then the statement print(a," is Maximum") executes and which gives output--> 5 is maximum.
if condition is false then print(b,"is Maximum") executes.


Example 1: Python script to check The person eligible for voting or not.


age=int(input("Enter Your age"))
# Python Ternary Operator
can_vote = true if age >= 18 else false
if can_vote:     #test-condition
   print(" Wellcome You are Eligible for Voting!. and your age is = ",age)
else:
   print(" OOps! You are not Eligible for Voting!. and your age is = ",age)


Output:
Enter Your age
18
Wellcome You are Eligible for Voting!. and your age is =18
Explanation:
After successful the program show message
" Enter Your age" and wait till we not enter age.
and the age entered is 18.
then statement can_vote = true if age >= 18 else false , which executes as successfully and assign true to can_vote because age=18.
then we have tested if can_vote: which true and thus shows output
"Wellcome You are Eligible for Voting!. and your age is =18"


Previous Topic:-->> Nested if else statement in Python || Next topic:-->>Python Conditional statements assignments