Regarding id() in python -


this question has answer here:

i have doubt regarding id() in python.

>>> x=2 >>> y=2 >>> id(x) 94407182328128 >>> id(y) 94407182328128 

but if same list,i different id's

>>> a=[1,2,3] >>> b=[1,2,3] >>> id(a) 139700617222048 >>> id(b) 139700617135528 

why so? why int type id's same , why different lists?

thanks in advance.

python doesn’t have variables c. in c variable not name, set of bits; variable exists somewhere in memory. in python variables tags attached objects.

example:

tags exaple image

regarding list part:

you created new reference .

more details illustrated in brilliant video:

https://www.youtube.com/watch?v=enlaee1c7x4


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -