Home / Python / Reference / Built-in functions

Python id() function

Return a number that identifies an object in memory.

Syntax

id(obj)

Two names refer to the same object exactly when their ids are equal, which is what is checks. Useful for understanding copying.

Parameters

objany object

Return value

int

Example

Code

a = [1, 2]
b = a
c = a.copy()
print(id(a) == id(b), a is b)
print(id(a) == id(c), a is c, a == c)

Output

True True
False False True

Related

Learn it step by step in the free lesson Lists & Tuples, with exercises that check your answers.