Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Priority of operators: > and == [duplicate]

Tags:

People also ask

What will be the priority order of operators of same priority?

Multiplication, division, and modulus are equal in precedence. Addition and subtraction are also equal in precedence. However, multiplication, division, and modulus have a higher precedence than addition and subtraction.

What is the order of precedence of operators?

The logical-AND operator ( && ) has higher precedence than the logical-OR operator ( || ), so q && r is grouped as an operand. Since the logical operators guarantee evaluation of operands from left to right, q && r is evaluated before s-- .


I'm trying to guess which operator has priority: > (greater than) or == (equal). This is my experiment:

>>> 5 > 4 == 1
False

As far as I know, this has two possible solutions.

>>> (5 > 4) == 1
True
>>> 5 > (4 == 1)
True

Neither one returns False, so how is the first code resolved by Python?