Test integerness: Difference between revisions
Content added Content deleted
(→{{header|Python}}: Updated to handle ints, floats, and complex types.) |
(→{{header|Python}}: Use is_integer()) |
||
Line 24: | Line 24: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
<lang python>>>> def isint(f): |
<lang python>>>> def isint(f): |
||
return complex(f).imag == 0 and |
return complex(f).imag == 0 and complex(f).real.is_integer() |
||
>>> [isint(f) for f in (1.0, 2, (3.0+0.0j), 4.1, (3+4j), (5.6+0j))] |
>>> [isint(f) for f in (1.0, 2, (3.0+0.0j), 4.1, (3+4j), (5.6+0j))] |