jeudi 26 novembre 2015

Inequalities and Parenthesis in Python

So in python, truth conditions can be easily checked and with parenthesis it prioritize the order of true conditions, e.g. these are easy to understand:

>>> 3 > 2
True
>>> (3 > 2) is True
True

But what does these mean, I couldn't grasp the logic of why they return False/True:

>>> 3 > 2 is True
False
>>> 3 > (2 is True)
True
>>> 5 < 3 is False > 2 is True
False
>>> 5 < 3 is False is True > 2 is True
False
>>> 3 < 5 is True is True > 2 is True
False
>>> 3 < 5 is True is True > 2 is True is not False is True
False
>>> 3 < 5 is True is (True > 2 is True is not False) is True
False
>>> 3 < 5 is True is (True > (2 is True) is not False) is True
False
>>> (3 < 5 is True is True) > 2 is (True is not False is True)
False

I know these are not pythonic conditions but how should I understand them? Is it still from left to right?

Or is is True and is False takes presidence?

Aucun commentaire:

Enregistrer un commentaire