473,587 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why is 'None' not assignable but 'True'/'False' are?

In Python 2.4.1:
None = 99 SyntaxError: assignment to None True = 99
False = 99
True == False

True
-----------------------
So why is 'None' special?

Jan 2 '06 #1
2 1572
Rodney Maxwell <ro************ @gmail.com> wrote:
In Python 2.4.1:
None = 99 SyntaxError: assignment to None True = 99
False = 99
True == False

True
-----------------------
So why is 'None' special?


A legacy/backwards compatibility issue: None has been there 'forever',
so that no sensible code ever had any business assigning to it; but
'False' and 'True' were introduced just a few years ago, and it was
important to not break sensible existing code doing something like

True = 1
False = 0

at the very start. In Python 3.0, when backwards compatibilities can be
introduced, True and False will become keywords (as will None); see
<http://www.python.org/peps/pep-3000.html>.
Alex
Jan 2 '06 #2
On 2006-01-02, Alex Martelli <al***@mail.com cast.net> wrote:
Rodney Maxwell <ro************ @gmail.com> wrote:
In Python 2.4.1:
>>> None = 99

SyntaxError: assignment to None
>>> True = 99
>>> False = 99
>>> True == False

True
-----------------------
So why is 'None' special?


A legacy/backwards compatibility issue: None has been there 'forever',
so that no sensible code ever had any business assigning to it; but
'False' and 'True' were introduced just a few years ago, and it was
important to not break sensible existing code doing something like

True = 1
False = 0

at the very start. In Python 3.0, when backwards compatibilities can be
introduced, True and False will become keywords (as will None); see


I don't think it would be a good idea to make them keywords.

If you want to turn these into keywords, the question pops up, why
only these. Don't we see a lot of example code that goes like this:

list = [ some, kind, of, list ]
str = "some string"

And often enough it is followed with the advise not to shadow builtins.

So if python goes the route of keywords, it seems that all builtins
should be turned into keywords and not just a few of them. But that
would make it impossible to do things like obj.str, just as it is
now impossible to have something like obj.raise or obj.if

I think a way to make a name not rebindable in a specific namespace
would be more appropiate.

--
Antoon Pardon
Jan 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
7103
by: M-a-S | last post by:
Can anybody explain this: Python 2.3 (#46, Jul 29 2003, 18:54:32) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> >>> None = 3 <stdin>:1: SyntaxWarning: assignment to None >>> False = 4 >>> True = 5 >>>
20
1718
by: flamesrock | last post by:
Well, after playing with python for a bit I came across something weird: The statement (1 > None) is false (or any other value above 0). Why is this? (The reason I ask is sortof unrelated. I wanted to use None as a variable for which any integer, including negative ones have a greater value so that I wouldn't need to implement any...
35
3366
by: Steven Bethard | last post by:
I have lists containing values that are all either True, False or None, e.g.: etc. For a given list: * If all values are None, the function should return None.
5
1541
by: Nicolas Couture | last post by:
Hi, Is it possible to generate a list of `None' ? opts.__dict__.values() below could be represented by --- def get_options(opts): """Return True or False if an option is set or not""" vals = opts.__dict__.values()
18
4982
by: Alan G Isaac | last post by:
>>None >= 0 False True Explanation appreciated. Thanks, Alan Isaac
3
3416
by: massysett | last post by:
I'm puzzled about part of the standard. 23.1 states that items stored in a container must be assignable. Therefore, the items in a map--that is, std::pair<const Key, valuemust be assignable. However, such a pair--with the const Key--is not assignable. My concern is more than academic; take for instance the following code to make a copy of a...
0
209
by: Reedick, Andrew | last post by:
a If name is None: Then name is NULL, nothing, nada, no object, no memory allocated, a NULL pointer If name is not None: Then name is an object. It's a pointer to some kind of allocated structure in memory. No idea if it contains a false or true value.
0
7915
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8205
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.