
Associativity of Operators in Python| CBSE class11| Computer Science
Dear Class 11th STUDENTS, ! Welcome to this tutorial of Associativity of Operator in Python from your CBSE class 11 of Computer Science Syllabus. In this tutorial, we shall be learning our chapter-4: Operators in Python from Unit 2: Programming and Computational Thinking (PCT-1) as CBSE BOARD suggested to learn about Associativity of Operator in Python to complete this section. After going through this tutorial, you will be able to understand the following topics from your latest syllabus 2025-26.
Unit 2: Programming and Computational Thinking (PCT-1)
Chapter 4: Operator Precedence & Associativity in Python :
- INTRODUCTION TO ASSOCIATIVITY.
- TYPES OF OPERATOR ASSOCIATIVITY
- How will you define operator associativity?
- Which operator has associativity from right to left?
- Which of these relational operator has highest operator precedence >= <= ==?
- Which of the following operators has its associativity from right to left in Python?
- Which operator has lowest precedence in Python?
I advice you to check the latest syllabus given by CBSE Board at its Official website: www.cbseacademic.nic.in Also, in this tutorial we will covers all necessary topics/concepts required to complete your exams preparations in CBSE classes 11th.
NOTE:
- We are also giving some important Questions & Answers for better understanding as well as preparation for your examinations.
- You may also download PDF file of this tutorial from our SHOP for free.
- For your ease and more understanding, we are also giving the video explanation class of each and every topic individually, so that you may clear your topics and get success in your examinations.
Introduction to Operator associativity
In python Operator associativity is the order in which operators of the same precedence are evaluated within an expression. When an expression contains operators with different precedence levels, higher precedence operators are evaluated first. However, when operators of the same precedence appear, associativity acts as a tie-breaker, determining the direction of evaluation.
For example, in the expression
10 – 5 – 2, both subtraction operators have the same precedence.
Their associativity determines whether the expression is evaluated as (10 – 5) – 2 or 10 – (5 – 2).
Types of associativity:
Left-to-right associativity:
Operators are evaluated from the left to the right of the expression. Most arithmetic operators, like addition (+), subtraction (-), multiplication (*), and division (/), exhibit left-to-right associativity.
Example: 10 / 2 * 3
Here, both division and multiplication have the same precedence and follow left-to-right associativity.
First, 10 / 2 is evaluated, resulting in 5.
Then, 5 * 3 is evaluated, resulting in 15.
Therefore, the expression evaluates to 15.
Right-to-left associativity:
Operators are evaluated from the right to the left of the expression. Assignment operators (=), compound assignment operators (e.g., +=, -=), and the conditional (ternary) operator (?:) typically exhibit right-to-left associativity.
Example: a = b = 10;
The assignment operator has right-to-left associativity.
First, b = 10 is evaluated, assigning the value 10 to b.
Then, a = b is evaluated, assigning the value of b (which is now 10) to a.
Therefore, both a and b will be assigned the value 10.
Associativity of Operators in Python?
Python allows multiple operators in a single expression as you have learnt above, e.g., a<b + 2<c or p<q>r etc.
If the operators used in an expression have different precedence, there is not any problem as Python will evaluate the operator with higher precedence first.
BUT what if the expression contains two operators that have the same precedence? In that case, associativity helps determine the order operations.
Associativity use the order in which an expression (having multiple operators of same precedence) is evaluated. Almost all the operators have left-to-right associativity except exponentiation (**), which has right-to left associativity.
That means, in case of multiple operators with same precedence, other than **, in same expression- the operator on the left is evaluated first and then the operator on its right and so on. For example, multiplication operator (*), division operator (/) and floor division operator (//) have the same precedence.
So, if we have an expression having these operators simultaneously, then the same-precedence-operators will be evaluated in left-to-right order. For example,
The first expression is evaluated in left to right order of operators as evident from the second expression evaluated that clearly make this order of valuation An expression having multiple ** operators is evaluated from right to left, i.e., 2 ** 3 ** 4 will be evaluated as 2 ** (3**4) and NOT AS (2**3) **4 Consider following example:
See the default order of evaluation (first expression) with the second expression where parentheses are added as per right to left associativity order and not like third expression that has parentheses from left to right order because exponentiation(**) has right to left associativity.
Exam Time
Chapter : Operators in Python
IMPORTANT QUESTIONS : Asked in examinations of Class 12th Computer Science
- What is operator associativity with example?
- Which operator follows right associative in Python?
- How will you define operator associativity?
- Which operator has associativity from right to left?
- Which of these relational operator has highest operator precedence >= <= ==?
- Which of the following operators has its associativity from right to left in Python?
- Which operator has lowest precedence in Python?