None

Ken Seehof kseehof at neuralintegrator.com
Tue Oct 23 20:10:19 EDT 2001


> Hi,
>
> just had to try that out...
>
> >>> print None
> None
> >>> None = 17
> >>> print None
> 17
> >>>
>
> Strange... is it intended that you can assign to None?
>
> In short, is this a bug or a feature?
>
> thanks
> Werner

When you understand why this is exactly what you would expect, your
understand of python will jump to the next level :-).

'None' is a name, not a keyword.  Assigning to None simply attaches a new
object to the name 'None'.  So it's not as scary as it looks.  You are not
changing the value of an internal variable as you might expect.  In other
languages such as C/C++ (which have early binding), assignment causes data
stored in a variable to change.  In python (and other languages with late
binding), assignment binds a name to some data without changing the data
that the name used to refer to.  This is probably the most important concept
for python programmers to understand if they come from a C/C++ background.

>>> x = None
>>> print x
None
>>> None = 'spam!'
>>> print None
spam!
>>> print x
None

Get it?

- Ken






More information about the Python-list mailing list