checking if a number is int
Steingrim Dovland
steingrd at student.matnat.uio.no
Sat Apr 6 12:39:53 EST 2002
Robert Spielmann <varial at gmx.de> writes:
> is there a way in python to check if a number is integer? My problem is
> the following: I need to know if sqrt(x) is an integer value or if there
> is a fractional part.
You can do it using the modulo-operator %. An integer value % 1
will return 0 and a non-integer value % 1 will return something
greater than 0.
>>> x = 5
>>> y = 5.33333
>>> x % 1
0
>>> y % 1
0.33333
steingrim dovland
--
Here the sea spray give
I was with her
We're under the ship so get me over
More information about the Python-list
mailing list