- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
The id() function in Python returns a unique and constant integer that identifies an object during its lifetime. In CPython, this value corresponds to the object’s memory address.
Example:
x = [1, 2, 3]y = xz = [1, 2, 3]print(id(x)) # Unique ID for xprint(id(y)) # Same as x (points to same object)print(id(z)) # Different from x and yprint(id(x) == id(y)) # Trueprint(id(x) == id(z)) # FalseCopied!✕CopyOutput:
140642115230496140642115230496140642115230800TrueFalseCopied!✕CopyHow it works
The id() function takes one object as an argument.
Returns an integer that is unique for the object during its lifetime.
Two variables referencing the same object will have the same id.
Once an object is destroyed (garbage collected), its id may be reused for new objects.
Common Use Cases
Checking if two variables point to the same object
a = "hello"b = "hello"print(id(a) == id(b)) # Often True due to string interningCopied!✕CopyDebugging reference issues
Python id () Function - W3Schools
The id() function returns a unique id for the specified object. All objects in Python has its own unique id. The id is assigned to the object when it is created.
Syntax
id(object)- People also ask
id () function in Python - GeeksforGeeks
Nov 29, 2023 · In Python, id () function is a built-in function that returns the unique identifier of an object. The identifier is an integer, which represents …
What is `id()` function used for in Python? - Stack Overflow
In my case, I have found the id() function handy for creating opaque handles to return to C code when calling python from C. Doing that, you can easily use a dictionary to look up the object …
- Reviews: 4
Python id Function - Complete Guide - ZetCode
Apr 11, 2025 · This comprehensive guide explores Python's id function, which returns the identity of an object. We'll cover object identity, memory addresses, and practical examples of object …
Python id () Function - Identification in Python
Learn how to use the built-in id() function in Python to get the unique identifier or memory address of any object. See examples of how to compare objects based on their ids and how to use id() …
Python id () Function - Online Tutorials Library
The Python id () function is used to obtain the unique identifier for an object. This identifier is a numeric value (more specifically an integer) that corresponds to the object's memory address …
Python id () Function: Use, Syntax, and Examples
Dec 7, 2024 · Python id () function: In this tutorial, we will learn about the id () function in Python with its use, syntax, parameters, returns type, and examples.
Python id (): Return the Identity of an Object
Learn how to use the id() function to return an integer that identifies an object in Python. See examples of how to use id() with numbers, strings, …