- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
id() function in Python
In this article, we will learn about the usage and implementation of id() function in Python 3.x. Or earlier. It is present in Python Standard Library and is automatically imported before executing the code.
Syntax: id (<entity name>)
Return value: Identity value of type <int>
The function accepts exactly one argument i.e. the name of the entity whose id has to be used. This id is unique for every entity until they are referring to the same data.
Id’s are merely address in the memory locations and is used internally in Python.
str_1 = "Tutorials" print(id(str_1)) str_2 = "Tutorials" print(id(str_2)) # This will return True as string values are identical print(id(str_1) == id(str_2)) # This will return False as string values are not identical str_1=str_1+str_2 print(id(str_1) == id(str_2)) # This will return True as string references are identical str_2=str_1 print(id(str_1) == id(str_2))
46939355256048 46939355256048 True False True
Here in case, 1 bool value True is displayed as both string variables contains the same type of data. Whereas in case 2 the contents of one of the variables are modified by concatenation operations and hence bool value False is displayed on the screen. In case 3 references to both the string variables are identical and hence True is displayed on the screen.
In this article, we learned how to implement the lambda and filter() functions in Python 3.x. Or earlier. We also learned about the combined usage of both functions to get the desired output.
- Generating random Id’s in Python
- Generating Random id's using UUID in Python
- How to get resource ID using get_resource_id() function in PHP and PHP 8?
- ID Selectors in CSS
- jQuery #id Selector
- HTML id Attribute
- How to validate an email id using regular expression in Python?
- Hide id field in MongoDB
- Iterator function in Python
- Calendar function in Python
- Function Annotations in Python
- Function Decorators in Python?
- isdisjoint() function in Python
- join() function in Python
- vars() function in Python