id() is one of Python's built-in functions, used to return the unique identifier of a given object, i.e., the object's address in memory.

Specifically, the id() function returns an integer representing the memory address of the given object. This value is unique throughout the object's lifetime. If two objects have the same id, they are the same object.

id() Function Examples

Here are examples using the id() function:

a = [1, 2, 3]

def print_id(x):
    print(id(x))

print(id(a))
print_id(a)      # Should be same as previous
print_id(a[:])   # Passing a copy to function, ID should differ from first two

Program Output

1913230990912
1913230990912
1913231066304