Created
February 15, 2018 17:38
-
-
Save marceloandriolli/583645d94a7a521f78f79ab44c8fb23f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python variables work more like labels than boxes. So it acknowledges that
'apple'
already exists and gets itsid
(source by @ramalho).