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 the most popular ide for python?

1 Answers  


What are key features of python?

1 Answers  


How do you escape a string in python?

1 Answers  


What is data type in python?

1 Answers  


What are operators?

6 Answers  


What are the use of sets in python?

1 Answers  


How to check the string consists of alphanumeric characters ?

1 Answers  


What are static methods for?

1 Answers  


What does means by split do in python?

1 Answers  


What does the meaning of slicing in python?

1 Answers  


Why python is faster than java?

1 Answers  


Is python a shell script?

1 Answers  


Categories