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 8755461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:51:56+00:00 2026-06-13T13:51:56+00:00

Possible Duplicate: Why does the expression 0 < 0 == 0 return False in

  • 0

Possible Duplicate:
Why does the expression 0 < 0 == 0 return False in Python?

The following output from the Python 2 REPL confuses me:

>>> 15>10==True
False
>>> 15>1==True
True
>>> 15>2==True
False
>>> 15>False
True

If 15>10==True is evaluated as (15>10)==True the expression would simplify to print True==True, which obviously evaluates to True. If 15>10==True is evaluated as 15>(10==True) the expression simplifies to 15>False which also evaluates to True. Both of these interpretations contradict the actual value of the expression (False).

I can understand 15>1==True evaluating to True since 1==True is true, but no interpretation of 15>10==True makes sense to me.

Summary: In Python 2, why does 15>10==True evaluate to False?

  • 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-13T13:51:57+00:00Added an answer on June 13, 2026 at 1:51 pm

    This is because chained comparison in Python. Namely, 15>10==True is actually evaluated as:

    15 > 10 and 10 == True
    

    which is False.

    On the other hand, 15>1==True is the same as

    15 > 1 and 1 == True
    

    which evaluates to True.


    To quote from the docs:

    Unlike C, all comparison operations in Python have the same priority, which is lower than that of any arithmetic, shifting or bitwise operation. Also unlike C, expressions like a < b < c have the interpretation that is conventional in mathematics:

    comparison    ::=  or_expr ( comp_operator or_expr )*
    comp_operator ::=  "<" | ">" | "==" | ">=" | "<=" | "<>" | "!="
                       | "is" ["not"] | ["not"] "in"
    

    Comparisons yield boolean values: True or False.

    Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z, except that y is evaluated only once (but in both cases z is not evaluated at all when x < y is found to be false).

    Formally, if a, b, c, …, y, z are expressions and op1, op2, …, opN are comparison operators, then a op1 b op2 c … y opN z is equivalent to a op1 b and b op2 c and … y opN z, except that each expression is evaluated at most once.

    Note that a op1 b op2 c doesn’t imply any kind of comparison between a and c, so that, e.g., x < y > z is perfectly legal (though perhaps not pretty).

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

Sidebar

Related Questions

Possible Duplicate: Does the compiler continue evaluating an expression where all must be true
Possible Duplicate: Why does parseInt(1/0, 19) return 18? I was parsing an integer from
Possible Duplicate: Does a finally block always run? let's imagine the following scenario: public
Possible Duplicate: Does HTML5 require clients to support JavaScript? Would HTML5 API's work when
Possible Duplicate: In what order does evaluation of post-increment operator happen? Consider the following
Possible Duplicate: php - regular expression - PCRE does not support \L, \l, \N,
Possible Duplicate: Does anyone know of a good C# API for Subversion? I'm designing
Possible Duplicate: Does fast enumeration in Objective-C guarantee the order of iteration? Just a
Possible Duplicate: How does this CSS triangle shape work? Please help me i need
Possible Duplicate: What does “(void) new” mean in C++? I'm not familiar with C++

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.