Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python why this if statement returns True?

I am wondering why it returns True:

if False or True and True == True and (False == True or False == (not True)) or False and False and True:
    pass

doesn’t it accept "and False" part in the end as False?
doesn’t all statements with "and" return True?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Starting with:

False or True and True == True and (False == True or False == (not True)) or False and False and True

Solve parentheses first:

(False == True or False == (not True))

Solve parentheses first – not True is False:

(False == True or False == False)

Next order of operation: ==:

((False == True) or (False == False))

Resulting in:

((False) or (True))

Next order of operation: or:

(True)

Now we have:

False or True and True == True and (True) or False and False and True

Next order of operation: ==:

False or True and (True == True) and True or False and False and True

Resulting in:

False or True and (True) and True or False and False and True

Next order of operation: and:

False or ((True and True) and True) or ((False and False) and True)

Resulting in:

False or ((True) and True) or ((False) and True)

And then:

False or (True) or (False)

Now the or operator:

((False or True) or False)

And then:

((True) or False)

Which results in True because True or False is True.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading