December 2017
Beginner
412 pages
10h 8m
English
Back in Values, Variables, and Computer Memory, you learned that Python keeps track of each value in a separate object and that each object has a memory address. You can discover the actual memory address of an object using 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) |
| | 4301189552 |
| | >>> id(23.1) |
| | 4298223160 |
| | >>> shoe_size = 8.5 |
| | >>> id(shoe_size) |
| | 4298223112 |
| | >>> fahrenheit = 77.7 |
| | >>> ... |
Read now
Unlock full access