Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108256 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2016-05-07 16:48 +1000 |
| Last post | 2016-05-07 16:48 +1000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Why do these statements evaluate the way they do? Chris Angelico <rosuav@gmail.com> - 2016-05-07 16:48 +1000
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2016-05-07 16:48 +1000 |
| Subject | Re: Why do these statements evaluate the way they do? |
| Message-ID | <mailman.447.1462603704.32212.python-list@python.org> |
On Sat, May 7, 2016 at 4:36 PM, Anthony Papillion
<anthony@cajuntechie.org> wrote:
> I'm trying to figure out why the following statements evaluate the way they do and I'm not grasping it for some reason. I'm hoping someone can help me.
>
> 40+2 is 42 #evaluates to True
> But
> 2**32 is 2**32 #evaluates to False
>
> This is an example taken from a Microsoft blog on the topic. They say the reason is because the return is based on identity and not value but, to me, these statements are fairly equal.
Frankly, you shouldn't care. Integers and strings should always be
compared for equality ("=="), not identity ("is"). Everything else is
an interpreter optimization; what you'll find is that some small
integers are cached deep within CPython, so the integer 7 is always
the same object. The exact set that's cached varies from version to
version of CPython, and other interpreters mightn't do that at all -
or might not even have actual in-memory objects for *any* integers in
the machine word range, using their values directly. Or anything at
all.
ChrisA
Back to top | Article view | comp.lang.python
csiph-web