Python Identity Operators

python-logical-operators

Identity Operators in Python.

In the Python programming language, identity operators are used to check if both values, variables, or constants are not only the same, but also have the same memory location.
To compare and check the exact match of values between two objects, these types of operators are used.

Identity Operators in Python

Identity Operators are used to compare the memory addresses of two objects to determine whether they refer to the same object or not. All  Identity operators in python are discussed below  in detail with their syntax and proper example:

1. Is

It is used testify whether two variables refer to the same object. It returns True if both the objects are the same objects else it returns False. It even returns False if both objects are equal but not refer to the same object.

Syntax

Variable1 is Variable2

Example

>>> a = 10
>>> b = 10
>>> a is b
True
>>> a is 10
True
>>> 10 is 10
True

2. Is Not

It is used testify whether two variables refer to the same object. It returns False if both the objects are the same objects else it returns True. It even returns True if both objects are equal but not refer to the same object.

Syntax

Variable1 is not Variable2

Example

>>> a = 10
>>> b = 10
>>> a is not b
False
>>> a is not 10
False
>>> 10 is not 10
False

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription