28.10.2021 Views

Python Tutorial ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

if ( id(a) == id(b) ):

print "Line 2 - a and b have same identity"

else:

print "Line 2 - a and b do not have same identity"

b = 30

if ( a is b ):

print "Line 3 - a and b have same identity"

else:

print "Line 3 - a and b do not have same identity"

if ( a is not b ):

print "Line 4 - a and b do not have same identity"

else:

print "Line 4 - a and b have same identity"

When you execute the above program, it produces the following result:

Line 1 - a and b have same identity

Line 2 - a and b have same identity

Line 3 - a and b do not have same identity

Line 4 - a and b do not have same identity

Python Operators Precedence

Operator precedence determines the grouping of terms in an expression. This affects how an expression is

evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has

higher precedence than the addition operator.

For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher precedence than +, so it

first multiplies 3*2 and then adds into 7.

Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the

bottom. Within an expression, higher precedence operators will be evaluated first.

The following table lists all operators from highest precedence to lowest:

Operator

Description

** Exponentiation (raise to the power)

~ + - Complement, unary plus and minus (method names for the last two are +@ and -@)

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!