How can the ternary operators be used in python?



How can the ternary operators be used in python?..

Answer / chaitanya

The ternary operator is the operator that is used to show the conditional statements. This consists of the true or false values with a statement that has to be evaluated for it. The operator will be given as:

[on_true] if [expression] else [on_false]

x, y = 25, 50

big = x if x < y else y

This is the lowest priority operator that is used in making a decision that is based on the values of true or false. The expression gets evaluated like if x<y else y, in this case if x<y is true then the value is returned as big=x and if it is incorrect then big=y will be sent as a result.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

How is python interpreted language?

0 Answers  


What mode is used for both writing and reading in binary format in file.?

0 Answers  


What is list when we have to use ?

0 Answers  


What is python orm?

0 Answers  


What are tuples used for?

0 Answers  






What are objects and classes in python?

0 Answers  


How do I use python idle?

0 Answers  


What is setuptools in python?

0 Answers  


What is class variable in python?

0 Answers  


Which package is the fastest form of python?

0 Answers  


Name some of the important modules that are available in python.

0 Answers  


Is print a function in python 3?

0 Answers  


Categories