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

What is nose python?

0 Answers  


What is sys stdout flush ()?

0 Answers  


What is map?

0 Answers  


Python has something called the dictionary. Explain using an example

0 Answers  


Explain me what is pass in python?

0 Answers  






What does the **kwargs do in python?

0 Answers  


How do you check if a list is empty in python?

0 Answers  


Describe about the libraries of python?

0 Answers  


Differentiate between django, pyramid, and flask?

0 Answers  


What is asynchronous python?

0 Answers  


Explain how you can minimize the memcached server outages in your python development?

0 Answers  


what is python?

8 Answers   Infosys,


Categories