Skip to content Skip to sidebar Skip to footer

Does The Id() Function In Python Create New Values?

I was just playing around with the id() function & noticed that if you pass a value that you haven't assigned to a variable yet, instead of giving an error it returns a memory

Solution 1:

Values/literals are objects, so id() will always return a valid result for them. Beyond that, in CPython integer literals from -1 through 256 as well as short string literals are interned, so they will have a constant ID after they have been accessed for the first time.


Post a Comment for "Does The Id() Function In Python Create New Values?"