I found an example which make me curious:
int = float
def parse_string(s):
return int(s)
print(parse_string('42'))
The returned result is 42.0. Int and float are build in functions. How come that we can assign float to int (build in functions)? It seems to be wired to me.
Python use references to objects.
When you write int = float, you only change the int reference to point to the same object (a built-in function here) than the one pointed by float reference.
You don't change the nature of int of course.
You can restore the int reference by importing __builtin__:
import __builtin__
int = __builtin__.int
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With