alternative
  • Home (current)
  • About
  • Tutorial
    Technologies
    C#
    Deep Learning
    Statistics for AIML
    Natural Language Processing
    Machine Learning
    SQL -Structured Query Language
    Python
    Ethical Hacking
    Placement Preparation
    Quantitative Aptitude
    View All Tutorial
  • Quiz
    C#
    SQL -Structured Query Language
    Quantitative Aptitude
    Java
    View All Quiz Course
  • Q & A
    C#
    Quantitative Aptitude
    Java
    View All Q & A course
  • Programs
  • Articles
    Identity And Access Management
    Artificial Intelligence & Machine Learning Project
    How to publish your local website on github pages with a custom domain name?
    How to download and install Xampp on Window Operating System ?
    How To Download And Install MySql Workbench
    How to install Pycharm ?
    How to install Python ?
    How to download and install Visual Studio IDE taking an example of C# (C Sharp)
    View All Post
  • Tools
    Program Compiler
    Sql Compiler
    Replace Multiple Text
    Meta Data From Multiple Url
  • Contact
  • User
    Login
    Register

Python - Things to know before proceed - Precedence & Associativity Of Operator Tutorial

​Precedence

In Expression, there can be one or more operators. To evaluate such type of expression there is the rule of Precedence in python

For example:-

Let consider an expression 10 + 5 * 3.

In the above expression * (multiplication) has higher precedence than + (addition).but we can change the order using parenthesis, as it has higher precedence than multiplication.

i.e (10 + 5) * 3

Precedence  Table ( Precedence in the below table will be in descending order. Upper Operator has higher precedence.)

Operator

Name as

Associativity

( )

Parenthesis

Left To Right

**

Exponent

Right To Left

+x , -x , ~x

Unary plus, Unary minus, Bitwise NOT

Left To Right

* , / , // , %

Multiplication, Division, Floor division, Modulus

Left To Right

+ , -

Addition, Subtraction

Left To Right

<< , >>

Bitwise shift operators

Left To Right

&

Bitwise AND

Left To Right

^

Bitwise XOR

Left To Right

|

Bitwise OR

Left To Right

== , != , > , >= , < , <= , is , is not , in , not in

Comparisons, Identity, Membership operators

Left To Right

not

Logical NOT

Left To Right

and

Logical AND

Left To Right

or

Logical OR

Left To Right

( 2 + 6 ) * ( 10 - 8 ) / 2 ** 3 % ( 5 // 2)Example:-

( 8 ) * ( 2 ) / 2 ** 3 % ( 2 )   #First Priority to Parenthesis

8 * 2 / 8 % 2    #Then exponent

16 / 8 % 2    #Then multiplication

2 % 2    #Then modulus

0

Associativity

Suppose in an expression, all the operators are of the same precedence, then associativity helps to determine the order of expression. Almost all operators have Left to Right associativity. Some of them have Right to Left associativity. 

For example:-

3 + 2 + 1  #It has Left to Right associativity

6

Another example with Right to Left associativity:-

3 ** 2 ** 3  #It will solve first 2 ** 3

3 ** 8

6561

Python

Python

  • Introduction
  • Installation and running a first python program
    • How to install Python ?
    • Running 1st Hello World Python Program
    • How to install Pycharm ?
  • Things to know before proceed
    • Escape Characters/Special Characters
    • Syntax ( Indentation, Comments )
    • Variable
    • Datatype
    • Keyword
    • Literals
    • Operator
    • Precedence & Associativity Of Operator
    • Identifiers
    • Ascii, Binary, Octal, Hexadecimal
    • TypeCasting
    • Input, Output Function and Formatting
  • Decision control and looping statement
    • if-else
    • for loop
    • While loop
    • Break Statement
    • Continue Statement
    • Pass Statement
  • Datatype
    • Number
    • List
    • Tuple
    • Dictionary
    • String
    • Set
    • None & Boolean
  • String Method
    • capitalize()
    • upper()
    • lower()
    • swapcase()
    • casefold()
    • count()
    • center()
    • endswith()
    • split()
    • rsplit()
    • title()
    • strip()
    • lstrip()
    • rstrip()
    • find()
    • index()
    • format()
    • encode()
    • expandtabs()
    • format_map()
    • join()
    • ljust()
    • rjust()
    • maketrans()
    • partition()
    • rpartition()
    • translate()
    • splitlines()
    • zfill()
    • isalpha()
    • isalnum()
    • isdecimal()
    • isdigit()
    • isidentifier()
    • islower()
    • isupper()
    • isnumeric()
    • isprintable()
    • isspace()
    • istitle()
  • Python Function
    • Introduction
  • Lambda Function
    • Lambda Function
  • Python Advanced
    • Iterators
    • Module
    • File Handling
    • Exceptional Handling
    • RegEx - Regular Expression
    • Numpy
    • Pandas

About Fresherbell

Best learning portal that provides you great learning experience of various technologies with modern compilation tools and technique

Important Links

Don't hesitate to give us a call or send us a contact form message

Terms & Conditions
Privacy Policy
Contact Us

Social Media

© Untitled. All rights reserved. Demo Images: Unsplash. Design: HTML5 UP.