Monday, 23 January 2017

OPERATORS PRECEDENCE IN PYTHON

Operator
Description
**
Exponentiation (raise to the power)
~, +, -
Complement, unary plus and minus
*, /, %, //
Multiply, Divide, Modulo and Floor
+, -
Addition and Subtraction
>>, <<
Right Shift and Left Shift
&
Bitwise AND
^, |
Bitwise exclusive OR or Regular OR
<=, <, >, >=
Comparison Operator
<>, ==, !=
Equality operator
=, %=, /=, //=, -=, +=, *=, **=
Assignment operator
is, is not
Identity operator
in, not in
Membership operators
not, or, and
Logical operators

Example 1 -
a=20
b=10
c=15
d=5
e=0
e=(a+b)*c/d
print 'value of (a+b)*c/d is ',e
e=((a+b)*c)/d
print 'value of ((a+b)*c)/d is ',e
e=(a+b)*(c/d)
print 'value of (a+b)*(c/d) is ',e
e=a+(b*c)/d

print 'value of a+(b*c)/d is ',e
Output -
value of (a+b)*c/d is  90
value of ((a+b)*c)/d is  90
value of (a+b)*(c/d) is  90

value of a+(b*c)/d is  50

No comments:

Post a Comment