Vivek
Vivek

Reputation: 33

Python: How does python executes multiple boolean in one statement?

With following condition, what should Python return? In which sequence the condition will get executed?

True or False and False and True

Upvotes: 3

Views: 182

Answers (2)

toom501
toom501

Reputation: 354

Like @Dean Dumitru has said and like it said in this answer here; the AND has a higher precedence than OR.

Hence, your condition could be rewritten in this way:

True or ((False and False) and True) -> True or (False and True) -> True or False -> TRUE

Upvotes: 1

Dean Dumitru
Dean Dumitru

Reputation: 39

AND has a higher precedence than OR.

True or False and False and True -> True or TRUE and True -> True or TRUE -> TRUE.

http://www.mathcs.emory.edu/~valerie/courses/fall10/155/resources/op_precedence.html

Upvotes: 3

Related Questions