test for None

Erik Max Francis max at alcyone.com
Tue Apr 18 21:16:04 EDT 2006


BartlebyScrivener wrote:

> How do you test for a function that returns nothing, and why doesn't
> this work? Shouldn't X have to be either None or not?
> 
>>>>x = None
>>>> for x in []:
> ... 	if x is None:
> ... 		print "X is None"
> ... 	else:
> ... 		print "X is not None"
> ... 		

No, because you're iterating over an empty list, which does nothing:

 >>> for x in []: print 'hi'
...
 >>>

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   The doors of Heaven and Hell are adjacent and identical.
   -- Nikos Kazantzakis



More information about the Python-list mailing list