How to test if a variable has a natural number?

Alexander Schmolck a.schmolck at gmx.net
Thu Jun 12 12:06:19 EDT 2003


pythonguy at Hotpop.com (Anand Pillai) writes:

> How about this...
> 
> from types import *
> 
> def natural(num):
>     if num>0 and type(num) is IntType:
>         return 1
>     else:
>         return 0

Nope. 

>>> natural(1L)
0


'as




More information about the Python-list mailing list