Site icon Meccanismo Complesso

Python Lessons – 2.5 The precedence of the operators

Python Lessons - 2.5 The precedence of the operators
Python Lessons - 2.5 The precedence of the operators

The precedence of the operators

The precedence of the operators is a very important concept in programming in general. In fact, the order in which operators are evaluated in the evaluation of an expression (including the conditions) is very important, both in mathematics and in programming itself.

Applying it to what we have said, comparison operators take precedence over Boolean operators when evaluating a condition.

There are conditions that test what we are saying.

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

In Python, the order of operator evaluation respects that of mathematics.

Tabella della precenza

**Exponent operator
∼,+,-Complement, positive or negative numbers
*,/,%,//Multiplication, division, module and rest
+, –Addition, subtraction
>>,<<Bitwise left and right
&Bitwise AND
^, |Bitwise XOR e OR
<=, <, >, >=Comparison operators
<>,==,!=Equality operators
=, %=, /=, //=,+=, -=, *=, **=Assignment operators
is, is notIdentity operators
in, not inMembership operators
not, or, andLogic operators

⇐ Go to Python Lesson 2.4 – Boolean Logic

Go to Python Lesson 2.6 – The WHILE Loop ⇒

Exit mobile version