You could also use the is_integral method of rational numbers:
sage: n = 3/2 + 1/2
sage: n.is_integral()
True
(This function also exists on Integers, so you could even use it in
situations where you weren't sure if you had an honest Integer or an
integer masquerading as a Rational.)
-cc
Another option is
sage: 3/2 + 1/2 in ZZ
True
sage: 3/2 + 1/3 in ZZ
False
- Robert
I just ran into the "True in ZZ" returns True thing again. How do I
check to see if I passed an option or "True"?
Nick
You can do "x is True"
- Robert
Also you could do
isinstance(x, bool) and x
but I like Robert's solution better.
William
snip
> [n for n in range(0,10) if is_Integer(n)]
You are doing this from the command line, yes? The first is getting
preparsed, so that 1 is not a python int, it is a sage Integer:
sage: preparse('[n for n in range(0,10) if is_Integer(n+1)]')
'[n for n in range(Integer(0),Integer(10)) if is_Integer(n+Integer(1))]'
sage: preparse('[n for n in range(0,10) if is_Integer(n)]')
'[n for n in range(Integer(0),Integer(10)) if is_Integer(n)]'
As for the warnings not being printed, in the loop you are maybe not
considered to be in Python global scope? I cannot say.
Nick