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
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:
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
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
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
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
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
--
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
-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
-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
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
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
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'
13 matches
Mail list logo