'if name is not None:' v. 'if name:'

2008-07-15 Thread Victor Noagbodji
Hello, what's the difference between these two statement? And which one should one use? -- NOAGBODJI Paul Victor -- http://mail.python.org/mailman/listinfo/python-list

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread J. Cliff Dyer
On Tue, 2008-07-15 at 14:37 -0400, Victor Noagbodji wrote: Hello, what's the difference between these two statement? And which one should one use? Aside: Please include all relevant information in the *body* of your post, not just the subject header. The two statements in question are:

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Larry Bates
Victor Noagbodji wrote: Hello, what's the difference between these two statement? And which one should one use? if name ... Will be false if: name is an integer == 0 name is a float == 0 name is an empty string name is an empty list name is an empty dictionary There are others, but you

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Fredrik Lundh
Victor Noagbodji wrote: 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

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Victor Noagbodji
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

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Russell Blau
Victor Noagbodji [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] 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? Because '' is a string value that is treated as false. If

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Jeffrey Froman
Victor Noagbodji wrote: Why do people use if name is not None: instead of simply writing if not name? To differentiate from the case where name == '', or some other non-None false value. So the question is, do you want to test for identity with None, or for truth in general? Jeffrey --

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Matimus
On Jul 15, 12:44 pm, Victor Noagbodji [EMAIL PROTECTED] wrote: 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

RE: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Reedick, Andrew
-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

RE: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Reedick, Andrew
-Original Message- From: [EMAIL PROTECTED] [mailto:python- [EMAIL PROTECTED] On Behalf Of Reedick, Andrew Sent: Tuesday, July 15, 2008 4:13 PM To: Victor Noagbodji; python-list@python.org Subject: RE: 'if name is not None:' v. 'if name:' If name: Then either

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Jerry Hill
On Tue, Jul 15, 2008 at 4:13 PM, Reedick, Andrew [EMAIL PROTECTED] wrote: If name is None: Then name is NULL, nothing, nada, no object, no memory allocated, a NULL pointer This is just plain untrue. If 'name is None' evaluates to true, then the variable 'name' is bound to the singleton

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Fredrik Lundh
Victor Noagbodji wrote: 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? Because they want to distinguish between None and other values that evaluate to False, of course. As the page

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Fredrik Lundh
Jerry Hill wrote: This is just plain untrue. If 'name is None' evaluates to true, then the variable 'name' is bound to the singleton value None. It has nothing to do with allocated memory or null pointers. All it means is that someplace along the line you did the equivalent of 'name = None'