How to test if a variable has a natural number?
Dan Bishop
danb_83 at yahoo.com
Thu Jun 12 19:56:43 EDT 2003
Alexander Schmolck <a.schmolck at gmx.net> wrote in message news:<yfsznknjn5w.fsf at black132.ex.ac.uk>...
> 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
How about...
def natural(num):
return num > 0 and num == long(num)
?
More information about the Python-list
mailing list