
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Why does the result of id() appear to be not unique in Python?
The id() method in Python return the identity of an object i.e. a unique id for the specified object. Now, you would be wondering, what is this id().
The id here is the object's memory address, an integer guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value.
Syntax
id(object)
This object can be object, String, Number, List, etc.
Unique id of List Object
Example
In this example, we will get the unique id of the list object using the id() −
myList = ["john", "tom", "henry", "mark"] res = id(myList) print(res)
Output
140571958913920
The id will be different when we will run it again:
140597372271552
Unique id of Tuple Object
Example
In this example, we will get the unique id of the Tuple object using the id() method −
myTuple = ("david", "steve", "alexa", "dwyer") res = id(myTuple) print(res)
Output
140389997162960
The id will be different when we will run it again −
140674820137424
Unique id of integers
Example
In this example, we will get the unique id of integers −
print(id(50)) print(id(100))
Output
140184574995904 140184574997504
- Related Articles
- Does ID have to be unique in the whole HTML page?
- Python + Selenium | How to locate elements in span class & not unique ID
- Why does the bottom of a tank or a pond containing water appear to be raised?
- Why does the sun appear red at sunrise?
- Why does the sun appear red at sunset?
- Why does the Sun appear reddish early in the morning?
- Why does the sky appear dark instead of blue to an astronaut?
- Filtering out the non-unique value to appear only once in JavaScript
- Why do backslashes appear twice while printing in Python?
- How to access unique Android device ID?
- Auto increment in MongoDB to store sequence of Unique User ID?
- If ([] == false) is true, why does ([] || true) result in []? - JavaScript
- Why the fire does not extinguish in cold?
- Why does ball not float in water?
- Why ship does not sink in sea?

Advertisements