- 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
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
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.
This object can be object, String, Number, List, etc.
Unique id of List Object
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)
The id will be different when we will run it again:
Unique id of Tuple Object
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)
The id will be different when we will run it again −
Unique id of integers
In this example, we will get the unique id of integers −
- 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?
- 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?
- Why the fire does not extinguish in cold?
- Why does ball not float in water?
- Why ship does not sink in sea?