(Apr-01-2017, 09:24 PM)ichabod801 Wrote:Ohh, now I got it.(Apr-01-2017, 09:04 PM)wavic Wrote: I think you can add the booleans to the list too.
I thought about that, because they are a subclass of int. However, they are singletons, which seems to put them in another category.
@Nirelg, the term 'singleton' relates to your question about the is operator. The is operator check the id() of a value, which is where it is stored in memory. So two ints with the same value may not 'is' the same because they are stored in different locations. Singleton means there is only ever one instance of True or False. They are always stored in the same location. None is another singleton.
But why would they have a different id?
I used the following code:
print type(2**11) print type(2**2) print id(2**11) print id(2**11) print id(2**2) print id(2**2)and the output is:
Output:<type 'int'>
<type 'int'>
46064336
46064324
45314908
45314908
They are both int after all, so why when I write twice 2**2 it gives me the same id yet when I do the same for 2**11 it gives them different ids?