Python Forum
Question about primitive variables.
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about primitive variables.
#14
(Apr-02-2017, 11:48 PM)micseydel Wrote:
(Apr-01-2017, 08:25 PM)Nirelg Wrote: why "2**32 is 2**32" gives us output of "False"?
Generally, is should not be used to compare ints (or for equality in general) in Python. The fact that for small values it does work is a consequence of an optimization - since the lower numbers are used so much, Python caches them to avoid having duplicates. It doesn't bother for higher numbers.

If that doesn't quite make sense, the wonderful video Ofnuts provided has a lot of good background information. Batchelder is great in general as well.
well, that is the problem.
It should not "bother" for higher numbers, but when i write the code:
print id(1000)
print id(1000)
They both have the same id even tho they are high numbers (even tried with higher numbers).
Output:
41870080 41870080
I also wrote "print 1000 is 1000" giving me "True", so why it works the same with higher numbers even tho it shouldn't?
keep in mind that when I write "2**10 is 2**10" it will write False! yet when doing it with the numbers them self (like 1000) it gives me True.

I watched the entire video, it helped me a lot to understand how python works, but it still did not solve the question why it gave me the same id when it should not have lol.
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 337 Apr-12-2024, 12:03 AM
Last Post: deanhystad
  Question regarding local and global variables donmerch 12 5,280 Apr-12-2020, 03:58 PM
Last Post: TomToad
  Question about naming variables in class methods sShadowSerpent 1 2,070 Mar-25-2020, 04:51 PM
Last Post: ndc85430
  Basic Pyhton for Rhino 6 question about variables SaeedSH 1 2,192 Jan-28-2020, 04:33 AM
Last Post: Larz60+
  A question about global variables Goldberg291 3 4,096 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