(0, 1) is a 2-element tuple . You can access your values ββusing the indexes for access [0] and [1] as follows:
>>> (0, 1)[0] 0 >>> (0, 1)[1] 1
Now, in Python, the Boolean values True and False are actually instances of int (because bool is a subtype of int ):
>>> issubclass(bool, int) True >>> isinstance(True, int) True >>> isinstance(False, int) True
The int True and False values ββare 1 and 0 :
>>> True == 1 True >>> False == 0 True
So, you can use their two element accesses in your 2-element tuple:
>>> (0, 1)[False] 0 >>> (0, 1)[True] 1
And this explains why a condition is returned here that returns a logical-work.
This is also mentioned in the documentation (my attention):
Booleans are two constant objects False and True . They are used to represent truth values ββ(although other values ββmay also be considered false or true). In numerical contexts (for example, when used as an argument to an arithmetic operator), they behave as integers 0 and 1, respectively.
source share