In , you learned that Python stores each value in a separate object. Every object in Python is tracked by the system and can be distinguished from other objects, even if they hold the same value. This distinguishing feature is called the object’s identity. An object’s identity is usually related to its unique memory address, though it isn’t guaranteed to be the actual address. You can find the identity of an object obj using the built-in function id:
| | >>> help(id) |
| | Help on built-in function id in module builtins: |
| | |
| | id(obj, /) |
| | Return the identity of an object. |
| | |
| | This is guaranteed to be unique among simultaneously existing objects. |
| | (CPython uses the object's memory address.) |
How cool is that? Let’s try it:
| | >>> id(-9) |
| | 140610723244688 |
| | >>> id(23.1) |
| | 140610725652592 |
| | >>> shoe_size = 8.5 |
| | >>> id(shoe_size) |
| | 140610727966896 |
| | >>> fahrenheit = 77.7 |
| | >>> id(fahrenheit) |
| | 140610725657616 |
The identities you get will likely be different from those listed here, as values are stored wherever there’s free space available.
Functions (function objects) also have identities:
| | >>> id(abs) |
| | 139816718551376 |
| | >>> id(round) |
| | 139816718554336 |