- what does this hex exactly mean? memory location?
Yes is the address of the object in memory. it is represented in hexadecimal number in order to make it more 'human readable.'
import sys
class Pokemon:
"This is a Pokemon class"
numner = 10
def birth(self):
print('Hello')
print(Pokemon)
#<class '__main__.Pokemon'>
print(Pokemon.birth)
#<function Pokemon.birth at 0x000001F83C177C10>
print(hex(id(Pokemon)))
#0x1f83bf6fad0
print(hex(id(Pokemon.birth)))
#0x1f83c177c10
print(Pokemon.birth.__repr__)
# <method-wrapper '__repr__' of function object at 0x0000018609D87C10>
Interesting features
Only the memory consumption directly attributed to the object is accounted for, not the memory consumption of objects it refers to.
print(sys.getsizeof(Pokemon))
print(sys.getsizeof(Pokemon.birth))
#1064
#136
- Reference Counts and Namespace
The code below show where the object Pokemon.birth leaves. It is not in the globals() namespace but rather within the '__main.__Pokemon' class namespace.
print(globals()['Pokemon'])
# <class '__main__.Pokemon'>
print(Pokemon.__dict__['birth'])
# <function Pokemon.birth at 0x0000020D51167C10>