Preguntas y respuestas
1. Dirección de memoria
Dado:
>>> def myfunc():¿ Qué representa 0xb5e4da04 ?
return 1
>>> myfunc
<function myfunc at 0xb5e4da04>
usando pydoc, vemos la documentación del módulo __builtin__
- id(...)
-
Return the identity of an object. This is guaranteed to be unique among
simultaneously existing objects. (Hint: it's the object's memory address.)
- hex(...)
- hex(number) -> string
Return the hexadecimal representation of an integer or long integer.
>>> myid = id(myfunc)
>>> hex(myid)
'0xb5e4da04L'
Otra forma de obtener la respuesta es en el canal de irc #python en el servidor irc.freenode.net:
(16:59:04) r0ver: Hello, i had defined a function called stuff. When i evaluate in python without arguments i get
<function stuff at 0xb7d79374> - what is the at 0xb7d79374 - i'd like to get more info about it.
(16:59:29) bobf: r0ver: It's the functions memory address.
(16:59:40) bobf: And you don't really need to know a great deal about it.
2. ¿ Se puede "invertir" las keys por valores y los valores por keys en un diccionario ?
No existe una función provista por el lenguaje que haga esto.Ver: Worthwhile to reverse a dictionary[1][2][3]