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 |
Have you heard of the yield keyword in python?
What is json? How would convert json data into python data?
Is python a nonetype?
Why python is best for data science?
How will you get a titlecased version of string?
Is python too slow?
What is tuple when we have to use ?
Why python is better?
How to import modules in python?
Differentiate between Pyramid, Django, and Flask
What are args and kwargs in Python?
How do you merge one dictionary with the other?