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

🚀 I'm Diwas Pandey, a Computer Engineer with an unyielding passion for Artificial Intelligence, currently pursuing a Master's in Computer Science at Washington State University, USA. As a dedicated blogger at AIHUBPROJECTS.COM, I share insights into the cutting-edge developments in AI, and as a Freelancer, I leverage my technical expertise to craft innovative solutions. Join me in bridging the gap between technology and healthcare as we shape a brighter future together! 🌍🤖🔬

View all posts by Diwas →

One Comment on “OPERATORS PRECEDENCE IN PYTHON”

Leave a Reply

Your email address will not be published. Required fields are marked *