0

What I know about id function is that it returns an unique number which works as identifier and represents the value position in memory. When I run id(some_constant_value) I'm getting an identifier, so that makes me think the constant value is already existed and created before any assignment.

It goes like this:

>>> id(1)
140736767556672
>>> a = 1
>>> id(a)
140736767556672
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Brad Figueroa
  • 869
  • 6
  • 15
  • That explains why the id is the same, if you were expecting `id()` not to have a value at all then that doesn't really make sense. – jonrsharpe Jul 07 '20 at 06:36
  • The behavior that both of them have same identifier value was what I expected. But why doesn't getting no value in `id()` make sense ? It's totally logical to think if we don't assign any value yet, the value in memory doesn't have to exist I guess – Brad Figueroa Jul 07 '20 at 13:38
  • Well in this case, per the dupe, `1` *did* exist before any assignment. But even for literals that *aren't* interned, the value still has to exist - if nothing else, it has to be passed to `id`! – jonrsharpe Jul 07 '20 at 13:40

0 Answers0