[Edu-sig] what is a "variable" in Python?

kirby urner kirby.urner at gmail.com
Thu Feb 18 14:53:48 EST 2016


On Thu, Feb 18, 2016 at 11:17 AM, Al Sweigart <al at inventwithpython.com>
wrote:



> Reference issue aside, I think the container works as a mental model. The
> problem with the tag/label model is that if you think of the variable
> `spam` as being attached to the value 42 and `eggs` as being attached also
> to 42, it brings up the confusing idea: why do you have separate 42s if you
> could just put both variable tag/labels on one 42? Where does this 42
> exist? Do all possible integers and strings just exist "out there", waiting
> to have a tag/label attached to them?
>

Would "yes" be a wrong answer?

>>> spam = eggs = 42
>>> id(spam) == id(eggs)
True

Two labels (two names), one thing (object, e.g. 42).

But no, they don't always all exist already because the types are the
birthing sources i.e. you need int, str, dict, tuple and so on to populate
the space with actual instances.  spam = 42 is short for spam = int('42',
10), where we're less fussy about base in the general sense.

If you *can* jettison containers, and just stick with pieces of paper, it's
lighter weight, conceptually.  I encourage the bucket kickers.  Hah hah.
As in "kicking the habit" of thinking "variables are buckets".  That's
early stages something not-so-healthy around Python, could be fine if
you're smoking C. :-D


Kirby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20160218/42b46034/attachment.html>


More information about the Edu-sig mailing list