checking if a number is int

Paul Rubin phr-n2002a at nightsong.com
Sat Apr 6 18:13:54 EST 2002


Johannes Gijsbers <taradino at softhome.net> writes:
> That's not really a good idea, as math.sqrt() returns a float. I'd say:
> 
> >>> import math
> >>> def isInt(number):
> ...     return int(number) == number
> ...
> >>> isInt(math.sqrt(289))
> 1
> >>> isInt(math.sqrt(315))
> 0

isInt(math.sqrt(1e100)) doesn't work so well.



More information about the Python-list mailing list