Skip to content

Instantly share code, notes, and snippets.

@marceloandriolli
Created February 15, 2018 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marceloandriolli/583645d94a7a521f78f79ab44c8fb23f to your computer and use it in GitHub Desktop.
Save marceloandriolli/583645d94a7a521f78f79ab44c8fb23f to your computer and use it in GitHub Desktop.
>>> fruit = 'apple'
>>> fruit is 'apple'
True
>>> fruit == 'apple'
True
>> id(fruit), id('apple')
(140031285906720, 140031285906720)
>>> id(fruit), id('orange')
(140031285906720, 140031285906912)
# why? How python infers that id of fruit is the same of 'apple', if a object has same value, would be same id?
@cuducos
Copy link

cuducos commented Feb 15, 2018

Python variables work more like labels than boxes. So it acknowledges that 'apple' already exists and gets its id (source by @ramalho).

@luzfcb
Copy link

luzfcb commented Feb 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment