Monday, 24 June 2019

Special Operators

Special Operators:

Python defines the following 2 special operators:

1. Identity operators
2. Membership operators


#Example program on Identity operators
a=10
b=10
print(a is b) #True
x=True
y=True
print(x is y) #True

Ex: 2:
>>> x=10
>>> y=20
>>> print(x is y)
False
>>> 
We can use identity operators for comparison. We have two identity operators:
is
is not
is operator:
a is b returns True if both a and b are pointing to the same object

Here addresses are comparing.

is not operators:


a=10
b=20

print(a is not b)
True
Ex2:
a=10
b=10
print(a is not b)
False

a is not b returns True if both a and b are not pointing to the same object.

Related Video: https://youtu.be/kyh9qQbf_uk

Next Topic: Membership Operators
Previous topic: Assignment operators


No comments:

Post a Comment

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(&qu...