How does python function return objects? -
in below diagram, have query on name temp returned function f

in local frame f, temp reference variable pointing object 6 of class int, when return temp in f reference variable output part of checkpassingmech frame point same object 6 temp pointing to.
my question:
q1) understanding correct?
q2) if q1 yes, diagram giving illusion temp not reference type , showing value in box rather arrow pointing 6, correct?
q3) if q2 yes, then, can 6 stored in heap , temp , output pointing heap space frame(local stack)
>>> def f(): temp = 6 print(id(temp)) return temp >>> output = f() 507107408 >>> id(output) 507107408 from doc:
cpython implementation detail: cpython, id(x) memory address x stored.
so strictly speaking, if value 6, output , temp pointing same object, int object cached when python started.
you may refer identifying objects, why returned value id(...) change? more information.
Comments
Post a Comment