0% found this document useful (0 votes)
60 views2 pages

Operator Precedence

The document explains operator precedence and associativity in Python, detailing how operators are evaluated in expressions. It highlights that most operators have left-to-right associativity, while the exponentiation operator (**) and logical not have right-to-left associativity. Several examples and CBSE 12th Board questions are provided to illustrate these concepts.

Uploaded by

shazamgaming2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views2 pages

Operator Precedence

The document explains operator precedence and associativity in Python, detailing how operators are evaluated in expressions. It highlights that most operators have left-to-right associativity, while the exponentiation operator (**) and logical not have right-to-left associativity. Several examples and CBSE 12th Board questions are provided to illustrate these concepts.

Uploaded by

shazamgaming2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

OPERATOR PRECEDENCE:

In Python, operator precedence determines the order in which operators are evaluated
in an expression. Operators with higher precedence are evaluated before operators
with lower precedence.

Associativity:
Associativity determines the order of evaluation when two operators of the same
precedence appear in an expression. Operators can have left-to-right or right-to-left
associativity.

All operators in the above given table except **, logical not have left to right
associativity.
** and logical not has right to left associativity
Example: left to right
print(10 / 5 * 2)
/ and * have the same precedence.
Since they follow left-to-right associativity:

 10 / 5 → 2.0 #10/5 will be evaluated first


 2.0 * 2 → 4.0

Output: 4.0

Example: right to left


print(2 ** 3 ** 2)
** follows right-to-left associativity.
So, it is evaluated as:

 3 ** 2 → 9
 2 ** 9 → 512

Output: 512
CBSE 12th Board questions:
1. not ((True and False) or True)
Ans: False
2. print(True or not True and False)
ANs : true
3. What will be the output of the following expression?
24//6%3 , 24//4//2 , 48//3//4
Ans: 1,3,4
4. print(25 // 4 + 3**1**2 * 2)
Ans : 12
5. print(2**3 + (5 + 6)**(1 + 1))
ANs : 129
6. print(16-(3+2)*5+2**3*4)
Ans: 23
7. 8 and 13 > 10
Ans : True
8. 7%5==2 and 4%2>0 or 15//2==7.5
Ans: False

You might also like