Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

ternary operator using dictionary in Python

# declaring python variables
num1 = 10
num2= 5
# python ternary operator using dictionary
result = {True: "num1 is larger", False: "num2 is larger"}[num1 > num2]
# printing
print(result)
Source by www.golinuxcloud.com #
 
PREVIOUS NEXT
Tagged: #ternary #operator #dictionary #Python
ADD COMMENT
Topic
Name
2+3 =