From: wheres pythonmonks on 5 Aug 2010 11:42 How does "x is not None" make any sense? "not x is None" does make sense. I can only surmise that in this context (preceding is) "not" is not a unary right-associative operator, therefore: x is not None === IS_NOTEQ(X, None) Beside "not in" which seems to work similarly, is there other syntactical sugar like this that I should be aware of? W
From: Roald de Vries on 5 Aug 2010 11:56 On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote: > How does "x is not None" make any sense? "not x is None" does make > sense. > > I can only surmise that in this context (preceding is) "not" is not a > unary right-associative operator, therefore: > > x is not None === IS_NOTEQ(X, None) > > Beside "not in" which seems to work similarly, is there other > syntactical sugar like this that I should be aware of? 'not None' first casts None to a bool, and then applies 'not', so 'x is not None' means 'x is True'. 'not x is None' is the same as 'not (x is None)' Cheers, Roald
From: Jean-Michel Pichavant on 5 Aug 2010 11:58 wheres pythonmonks wrote: > How does "x is not None" make any sense? "not x is None" does make sense. > > I can only surmise that in this context (preceding is) "not" is not a > unary right-associative operator, therefore: > > x is not None === IS_NOTEQ(X, None) > > Beside "not in" which seems to work similarly, is there other > syntactical sugar like this that I should be aware of? > > W > x is not None === not (x is None). "is not" is an operator, not the combination of 2. JM
From: Ben Finney on 5 Aug 2010 11:59 wheres pythonmonks <wherespythonmonks(a)gmail.com> writes: > How does "x is not None" make any sense? In two ways: partly from the fact that Python syntax is preferentially designed to be reasonably readable to a native English reader; and partly because it makes for more obvious semantics. 'is not' is a single operator which makes operator precedence clear, and also “x is not None” is gramatically good English. > "not x is None" does make sense. It unfortunately makes for awkward English, and it also makes for two separate operators and hence non-obvious operator precedence. > I can only surmise that in this context (preceding is) "not" is not a > unary right-associative operator Rather than surmise, you can read the language reference <URL:http://docs.python.org/reference/expressions.html#isnot> which makes clear that 'is not' is one operator. -- \ “I am amazed, O Wall, that you have not collapsed and fallen, | `\ since you must bear the tedious stupidities of so many | _o__) scrawlers.” —anonymous graffiti, Pompeii, 79 CE | Ben Finney
From: wheres pythonmonks on 5 Aug 2010 12:07
Well, I am not convinced of the equivalence of not None and true: >>> not None True >>> 3 is True; False >>> 3 is not None True >>> P.S. Sorry for the top-post -- is there a way to not do top posts from gmail? I haven't used usenet since tin. On Thu, Aug 5, 2010 at 11:56 AM, Roald de Vries <downaold(a)gmail.com> wrote: > On Aug 5, 2010, at 5:42 PM, wheres pythonmonks wrote: >> >> How does "x is not None" make any sense? "not x is None" does make sense. >> >> I can only surmise that in this context (preceding is) "not" is not a >> unary right-associative operator, therefore: >> >> x is not None === IS_NOTEQ(X, None) >> >> Beside "not in" which seems to work similarly, is there other >> syntactical sugar like this that I should be aware of? > > 'not None' first casts None to a bool, and then applies 'not', so 'x is not > None' means 'x is True'. > 'not x is None' is the same as 'not (x is None)' > > Cheers, Roald > -- > http://mail.python.org/mailman/listinfo/python-list > |