> -----Original Message----- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of Victor Noagbodji > Sent: Tuesday, July 15, 2008 3:44 PM > To: python-list@python.org > Subject: Re: 'if name is not None:' v. 'if name:' > > >>what's the difference between these two statement? > >one checks if the given object is not None, the other checks if it's a > true value: > >http://docs.python.org/ref/Booleans.html#Booleans > >>And which one should one use? > >depends on what you want to test for, of course. > > > ></F> > > Well that's exactly why I'm asking. Since None returns False in if > statements. Why do people use if name is not None: instead of simply > writing if not name? >
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. If name: Then either a) name is an object, and that object does not have a 'false' value, such as False, zero, or empty. or b) name is NULL/None. No object. Try this: d = dict() if not d: d['a'] = 1 print d d = None if not d: d['c'] = 3 print d ***** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA622 -- http://mail.python.org/mailman/listinfo/python-list