None, False, True

Gregor Lingl glingl at aon.at
Wed Sep 17 17:00:23 EDT 2003


M-a-S schrieb:

> Can anybody explain this:
> 
> Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> 
>>>>None = 3
> 
> <stdin>:1: SyntaxWarning: assignment to None
> 

Interestingly this doesn't occur in IDLE:

Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
...
IDLE 1.0
 >>> None = 3
SyntaxError: assignment to None (<pyshell#0>, line 1)
 >>> print None
None

In a recent posting to this list I asked how to write-protect
names. This seems to be done here with the Name None.
But again: how is it done?

----
On the other side the existence and knowledge of the None-object
doesn't disappear completely in the plain Python interpreter:

 >>> None = 3
<stdin>:1: SyntaxWarning: assignment to None
 >>> None
3
 >>> def f():
...     pass
...
 >>> print f()
None

But:

 >>> def g():
...     return None
...
 >>> g()
3

So you can use f to restore the value of None
(if you happened to forget to save it):

 >>> None = f()
<stdin>:1: SyntaxWarning: assignment to None
 >>> None
 >>> print None
None





More information about the Python-list mailing list