What's the address for?

Chris Angelico rosuav at gmail.com
Mon Feb 18 15:10:06 EST 2019


On Tue, Feb 19, 2019 at 7:04 AM Avi Gross <avigross at verizon.net> wrote:
> How about functions?
>
> Even more confusing:
>
> >>> def a(): pass
>
> >>> def b(): pass
>
> >>> id(a), id(b)
> (13123280, 13201816)
> >>> b=a
> >>> id(a), id(b)
> (13123280, 13123280)
> >>> def a(): return True
>
> >>> id(a), id(b)
> (13201816, 13123280)
>
> The above shows that making two independent (albeit otherwise minimally
> identical) functions makes two different id and copying one to the other
> makes them the same but then changing one gets back the same ID reused!

Actually, this part isn't explained by the id() docs. To understand
this, you need to go back to something even more basic: the meaning of
assignment. You did not copy one to the other. You simply changed name
bindings. Here. Read.

https://nedbatchelder.com/text/names1.html

ChrisA


More information about the Python-list mailing list