Getting Started

Python - IntroductionPython - Hello World ProgramPython - SyntaxPython - Data TypesPython - Variables

Operators

Python - Arithmetic OperatorsPython - Relational OperatorsPython - Logical OperatorsPython - Assignment OperatorsPython - Bitwise OperatorsPython - Membership OperatorsPython - Identity OperatorsPython - Increment and Decrement Operators

Conditions

Python - If Else statement

Loop

Python - While LoopPython - For Loop

Numbers

Python - NumbersPython - Number Conversion

Strings

Python - StringsPython - String OperatorsPython - String FormattingPython - String MethodsPython - String Format Method

List

Python - ListPython - List Methods

Tuple

Python - Tuple

Set

Python - SetPython - Set Methods

Dictionary

Python - DictionaryPython - Dictionary Methods

Functions

Python - FunctionsPython - Functions - Variable length argumentsPython - Lambda Function

Scope of Variables

Python - Scope of Variables

Modules

Python - ModulesPython - Math ModulePython - JSON ModulePython - datetime ModulePython - time Module

I/O

Python - Read input from keyboard

File

Python - File Handling

Exception Handling

Python - Exception Handling

OOP

Python - Classes and ObjectsPython - Class Constructor __init__ methodPython - Class Destructor __del__ methodPython - Built-in Class AttributesPython - InheritancePython - Method OverridingPython - Method Overloading

Package Management

Python - PIP

Python - MySQL

Python - MySQL - Getting StartedPython - MySQL - Insert dataPython - MySQL - Select dataPython - MySQL - Update dataPython - MySQL - Delete data

Python - CSV

Python - Read data from CSV filePython - Write data in CSV file

Python - Identity Operators

Python

python logo

In this tutorial we will learn about Identity operators in Python.

We use the identity operator to check the memory locations of two objects.

Following are the identity operators in Python

The is operator

This operator returns True if both the variables point at the same object.

Example #1

In the following example we have two integer variables having same value and we are checking if they are identical.

# variables
x = 10
y = 10

result = x is y

print("result:", result)

We will get True because both x and y are identical.

We can also check the id of the variables using the id() function.

The id() function returns a unique id for a given object.

Every object in Python gets a unique id when they are created.

The id of an object is an integer value that represents the address of an object in memory.

In the following example we are checking if the two variables are identical and also printing their id value.

# variables
x = 10
y = 10

result = x is y

print("result:", result, id(x), id(y))

The above code will give us a similar output as shown below.

result: True 4488129824 4488129824

The is not operator

This operator returns True if both the variables does not point at the same object.

Example #1

In the following example we have two variables having different values and we are checking if they are not identical.

# variables
x = 10
y = "Super"

result = x is not y

print("result:", result, id(x), id(y))

The above code will give a similar output.

result: True 4372065568 4374307928

We are getting True because both x and y are not identical.