OPERATORS PRECEDENCE IN PYTHON

Python Free Tutorial

Generally, combination of variables, operators is termed as an expression. To evaluate these type of expressions there is a rule of precedence in Python. 1 is the highest & 13 is the lowest precedence and precedence decreases from left to right.

1. ()             Parentheses
2. **             Exponent
3. +x, -x, ~x     Unary plus, Unary minus, Bitwise NOT
4. *, /, //, %    Multiplication, Division, Floor division, Modulus
5. +, -           Addition, Subtraction
6. <<, >>         Bitwise shift operators
7. &              Bitwise AND
8. ^              Bitwise XOR
9. |              Bitwise OR
10. ==, !=, >,    Comparisions, Identity, Membership operators
 >=, <, <=, is,
 is not, in, not in 
11. not           Logical NOT
12. and           Logical AND
13. or            Logical OR

EXAMPLE 01:

>>> print ( 10*9//4 )

Expected outtput : 20
Output Obtained  : 22

This page is contributed by Diwas & Sunil . If you like AIHUB and would like to contribute, you can also write an article & mail your article to  itsaihub@gmail.com . See your articles appearing on AI HUB platform and help other AI Enthusiast.

About Diwas Pandey

Highly motivated, strong drive with excellent interpersonal, communication, and team-building skills. Motivated to learn, grow and excel in Data Science, Artificial Intelligence, SEO & Digital Marketing

View all posts by Diwas Pandey →

One Comment on “OPERATORS PRECEDENCE IN PYTHON”

Leave a Reply

Your email address will not be published.