Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52359

Re: Python Basic Doubt

References (5 earlier) <5206DDED.8030506@islandtraining.com> <CAPTjJmrUGWnQ40iPiJtdKAB8WTbjRaM+bzUmukY6Cb4FvOi2JQ@mail.gmail.com> <5207034A.6070608@islandtraining.com> <CAPTjJmoj5K838vfjuEx9HGDuSb_Uq3=OckqksEk0YsM5Qb4P2w@mail.gmail.com> <52071320.9090308@islandtraining.com>
Date 2013-08-11 05:51 +0100
Subject Re: Python Basic Doubt
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.466.1376196698.1251.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Aug 11, 2013 at 5:29 AM, Gary Herron
<gary.herron@islandtraining.com> wrote:
> A beginner, on his first program or two, can understand 1, and perhaps
> parrot 2 without understanding (or needing to).   But the step from there to
> 3 is huge.  It's folly to dump that on a first-time programmer.  (It's
> probably even folly to dump that on a seasoned programmer just starting in
> Python.  I still remember not understanding the explanation for "is" when I
> first read it.  And it continued to make no sense until I had enough
> experience to understand the difference betwen C/C++ assignment to variables
> and Python's binding of variables.)

See, that's where the problem is. You will never grok the difference
between == and is if you're still thinking about C variables. (Though
you *might* be able to explain it by talking solely about char* and
the way two C strings can be the same but stored at different places
in memory. But that would be unhelpful most of the time.)

This is important *early* reading for a new Python programmer:

http://mail.python.org/pipermail/tutor/2010-December/080505.html

Note that it was originally posted on python-tutor, so it was
definitely aimed at the inexperienced.

> On 08/10/2013 08:43 PM, Chris Angelico wrote:
> Granted, English is a poor litmus test for code. But in this
> particular example, we're talking about immutable types (simple
> integers), where value and identity are practically the same. A Python
> implementation would be perfectly justified in interning *every*
> integer, in which case the 'is' would work perfectly here. The
> distinction between the two is important when the objects are mutable
> (so they have an identity that's distinct from their current values).
>
>
> Granted.  But please note:  There is *nothing* in that sentence which is fit
> for a beginner programmer.  ... "immutable", "value/identity", "interning"
> ...  In one ear and out the other. :-)

Right. This isn't my explanation of 'is' and '=='; it's my explanation
of why it's important to HAVE an explanation of the aforementioned. :)
Though the difference between value and identity is significant and
important, and mutability is bound to crop up fairly early on; so
really, it's only the concept of interning that would be really
advanced.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python Basic Doubt Chris Angelico <rosuav@gmail.com> - 2013-08-11 05:51 +0100

csiph-web