Branching on type
I want to produce a table of numbers. If the number is an integer then I just want to show that integer. If it is a float then I want to show that float, formatted to some number of places. I want a test roughly like this.
if type(x) == int:
outstring-= str(x)
else
outstring = "{:.3f}".format(x)
But I can't hit on the correct type test. If you ask for type(x)
then you get <class 'sage.rings.integer.Integer'>
and putting that into the test doesn't work for me. How to do that? (If I am doing it all wrong, Id love to hear that also.)
If you want to keep a test on
type(x)
, it should be written astype(x) == sage.rings.integer.Integer
.