Python Forum
Question about primitive variables.
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about primitive variables.
#8
(Apr-01-2017, 09:24 PM)ichabod801 Wrote:
(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.
Ohh, now I got it.
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?
Reply


Messages In This Thread
Question about primitive variables. - by Nirelg - Apr-01-2017, 05:06 PM
RE: Question about primitive variables. - by Nirelg - Apr-01-2017, 08:25 PM
RE: Question about primitive variables. - by wavic - Apr-01-2017, 09:04 PM
RE: Question about primitive variables. - by Nirelg - Apr-01-2017, 10:27 PM
RE: Question about primitive variables. - by wavic - Apr-01-2017, 09:52 PM
RE: Question about primitive variables. - by Nirelg - Apr-02-2017, 10:11 PM
RE: Question about primitive variables. - by Ofnuts - Apr-02-2017, 08:37 PM
RE: Question about primitive variables. - by wavic - Apr-03-2017, 12:13 AM
RE: Question about primitive variables. - by Nirelg - Apr-03-2017, 01:01 AM
RE: Question about primitive variables. - by casevh - Apr-03-2017, 02:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Very Beginner question on simple variables Harvy 1 235 Apr-12-2024, 12:03 AM
Last Post: deanhystad
  Question regarding local and global variables donmerch 12 5,190 Apr-12-2020, 03:58 PM
Last Post: TomToad
  Question about naming variables in class methods sShadowSerpent 1 2,037 Mar-25-2020, 04:51 PM
Last Post: ndc85430
  Basic Pyhton for Rhino 6 question about variables SaeedSH 1 2,169 Jan-28-2020, 04:33 AM
Last Post: Larz60+
  A question about global variables Goldberg291 3 4,040 Feb-02-2017, 10:50 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020