Python id() built-in function

From the Python 3 documentation

Return the “identity” of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value.

Introduction

The id() function returns a unique integer that identifies an object in memory. This ID is guaranteed to be unique for the lifetime of the object. It’s essentially the memory address of the object.

Examples

x = 10
y = 10
z = 20

print(id(x))  # Output might be something like 4331368528
print(id(y))  # Output will be the same as id(x) because Python caches small integers
print(id(z))  # Output will be different
print(id(1))
print(id('1'))
print(id([1, 2]))

Subscribe to pythoncheatsheet.org

Join 16,702+ Python developers in a two times a month and bullshit free publication , full of interesting, relevant links.