Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How can the ternary operators be used in python?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is pytest?

820


You mentioned pypi in your previous answer. Can you elaborate?

837


What is the difference between = and == in python?

1876


Is python or r more useful?

774


What is a decorator in python?

833


What is python and explain some of its benefits?

772


What does while 1 mean in python?

736


What is casting in python?

887


What is the difference between old style and new style classes in python?

811


What is the incorrect declaration of a set?

901


What is lambda function ?

838


What does * args mean in python?

826


How to get the ascii value in python?

935


What is GIL? What does it do?Talk to me about the GIL. How does it impact concurrency in Python? What kinds of applications does it impact more than others?

809


Where can I learn python for free?

749