python - Assignment build in functions -
i found example make me curious:
int = float def parse_string(s): return int(s) print(parse_string('42'))
the returned result 42.0
. int , float build in functions. how come can assign float int (build in functions)? seems wired me.
python use references objects.
when write int = float
, change int
reference point same object (a built-in function here) 1 pointed float
reference.
you don't change nature of int
of course.
you can restore int
reference importing __builtin__:
import __builtin__ int = __builtin__.int
Comments
Post a Comment