checking whether a var is empty or not

Pierre-Frédéric Caillaud peufeu at free.fr
Fri Jul 30 08:44:05 CEST 2004



	This smells like PHP to me...

if var is not None:
	if var has not been assigned, it raises an exception.
	if var has been assigned, it contains a value which can be None or  
someting else.

	This is different from PHP where you can't know if a variable exists or  
not, because a non-existent variable will contain null if you check it,  
and putting null in a variable is like deleting it, but noone knows  
because there's no way of checking if a variable really exists, etc.


> Are these equivelent? Is one approach prefered over the other
>
> #check to see if var contains something... if so proceed.
> if var is not None:
>      continue
>
> #check to see if var is empty... if so prompt user again.
> if not var:			
>     print "Please specify the amount."
>     ...




More information about the Python-list mailing list