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

Who developed python?

0 Answers  


What is the proper way to say good bye to python?

0 Answers  


What is the starting point of python code execution?

0 Answers  


What is a function call or a callable object in python?

0 Answers  


Name few python web frameworks for developing web applications?

0 Answers  






What is the sleeping time of giraffe?

0 Answers  


How can you create a copy of an object in python?

0 Answers  


Does python support inheritance?

0 Answers  


What is the namespace in python?

0 Answers  


What is memory management in python?

0 Answers  


What is pylintrc?

0 Answers  


What is %s %d in python?

0 Answers  


Categories