Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9216821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:29:53+00:00 2026-06-18T02:29:53+00:00

I have been reading all over the place, including Does Python have a ternary

  • 0

I have been reading all over the place, including Does Python have a ternary conditional operator?. It is supposed that

result = a if a > b else b

is better code than

result =  a > b and a or b

But no one ever explains why. Will someone please elaborate?

If it’s mere readability, then it’s really just a matter of preference: some people will like the one and some people will like the other. So my question is: is there some really technical advantage for going one way versus the other.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:29:54+00:00Added an answer on June 18, 2026 at 2:29 am

    result = a if a > b else b is better because it is always semantically correct. In other words, you will always get what you expect from it, regardless of the value of either a or b. result = a > b and a or b will result in b every time if a is a falsey value (0, None, etc).

    Additionally, since a if x else b is a specifically defined language construct, it will typically be easier for other Python developers to understand. Ultimately, anyone reviewing or maintaining your code should have to do as little mental wrangling as possible to understand what’s going on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been reading all over the web about this and still can't understand
I have been reading up on the changes that .NET4.5 will bring, and on
I have been looking all over the Internet for an answer to this question
I have been reading up on DDD a lot over the last few days
I have been all over this one, and I am just plumb stuck. I
Wow I've been all over the place with questions today and I apologize if
I have been searching all over the net to try and find a way
I am slowly learning C, but not very well. I have been reading over
I have just been reading over some of my old oo design books and
I've searched all over and have been trying for a few weeks now (and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.