In an interactive session like the following one:
>>> f=open('test.txt','w')
>>> f
<open file 'test.txt', mode 'w' at 0x6e610>
what does 0x6e610 represents and what could i do with that hexadecimal number in python?
In an interactive session like the following one:
>>> f=open('test.txt','w')
>>> f
<open file 'test.txt', mode 'w' at 0x6e610>
what does 0x6e610 represents and what could i do with that hexadecimal number in python?
It's the ID of the object, which (in standard Python) is its address in memory.
You can also get it via the id(obj)
function.
You can use IDs to tell whether two references refer to the same object - when you say if x is y
in Python, you're comparing IDs.
>>> f=open('test.txt')
>>> f
<open file 'test.txt', mode 'r' at 0x10047c938>
>>> hex(id(f))
'0x10047c938'
Have a look at id in the official documentation:
Return the “identity” of an object. This is an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value.
It is the memory offset of the Python object. Two objects are strictly same if they have same memory offset.
In Java, the similar thing is the hashCode.