This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: boolean operation issue (True == False == False)
Type: behavior Stage: resolved
Components: Parser Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, jmsohn.x, lys.nikolaou, pablogsal
Priority: normal Keywords:

Created on 2022-02-10 00:55 by jmsohn.x, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg412961 - (view) Author: jung mo sohn (jmsohn.x) Date: 2022-02-10 00:55
In python 3.6.8, 3.7.3, 3.7.4, 3.7.5, 3.7.12, 3.8.8 versions, the output is False as shown below.

Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 15 2019, 00:11:34) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print(True == False == False)
False

However, in the openjdk1.8 version, the output is "true" as shown below. 

public class Test {
	public static void main(String[] args) throws Exception{
		System.out.println(true == false == false);
	}
}

> java Test
true

In my opinion, "True" seems to be correct.
msg412964 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-02-10 01:09
This is not a bug. Please check the docs on the ternary operator:

https://docs.python.org/3/reference/expressions.html#comparisons

In particular:

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).



THis means that

True == False == False is really True == False and False == False wich is False and True which is False
msg412968 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2022-02-10 02:03
> True == False == False is really True == False and False == False 
> wich is False and True which is False

Moreover, since the left-hand comparison is `True == False`, which evaluates to False, the right-hand comparison doesn't even get evaluated. 

In the following example, print(3) doesn't get called because the left-hand comparison, `None != None`, is False:

    >>> print(1) != print(2) == print(3)
    1
    2
    False
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90859
2022-02-10 02:03:08eryksunsetnosy: + eryksun
messages: + msg412968
2022-02-10 01:09:08pablogsalsetmessages: + msg412964
2022-02-10 01:08:46pablogsalsetmessages: - msg412963
2022-02-10 01:08:20pablogsalsetstatus: open -> closed
resolution: not a bug
messages: + msg412963

stage: resolved
2022-02-10 00:55:12jmsohn.xcreate