How to test if a variable has a natural number?
exarkun at intarweb.us
Thu Jun 12 01:46:26 CEST 2003
On Wed, Jun 11, 2003 at 10:53:24PM +0000, Jack Daniel wrote:
> Martin P<martin_p at despammed.com> wrote:
> > how can I find out if the number of a variable
> > is a natural number or not?
> I'll asume that by "find out if the number of a variable
> is a natural number or not" you are asking how to determine whether the
> number a varible is set to is a Natural Number (ie in the set of whole
> positive numbers; a positive integer).
> If this is the case here we go:
> def natural(x):
> if x >= 1 & x % 1 == 0:
The preferred way to spell this is with "and", not "&". The semantics are
slightly different, and the operation you're really looking for is boolean
and, not bitwise and.
> print "Varible is set to a NATURAL"
> print "Varible is NOT set to a natural"
> run this lil snippet with the name of your varible as arg x
A disciple of another sect once came to Drescher as he was eating his
morning meal. "I would like to give you this personality test," said the
outsider, "because I want you to be happy." Drescher took the paper that was
offered him and put it into the toaster: "I wish the toaster to be happy,
More information about the Python-list