Program to demonstrate ternary operators in Python
marks =input('Enter the marks: ')print("The result is Pass"ifint(marks)>=35else"The result is Fail")
smaller, larger =7,50# Copy value of a in min if a < b else copy bmin= smaller if smaller < larger else larger
print(min)#equivalent to the (condition)?(if true) :(if false) in javascript
MALE =True
FEMALE =False# (if_test_is_false, if_test_is_true)[test]
gender =("female","male")[MALE]print("You are a ","male")# Output: You are a male# (if_test_is_false, if_test_is_true)[test]
gender =("female","male")[FEMALE]print("You are a ","female")# Output: You are a female
condition =True# (if_test_is_false, if_test_is_true)[test]print(2if condition else1/0)#Output is 2
condition =False# (if_test_is_false, if_test_is_true)[test]print(2if condition else5)#Output is 5