If you want to print all numbers in L1
, use:
for x in L1: print '%.2f' % x
If you want to skip the first one, for x in L1[1:]:
will work.
Edit: the OP mentions in a comment (!) that their desire is actually to "create a new array" (I imagine they actually mean "a new list", not an array.array
, but that wouldn't be very different). There are no "rounded numbers" in the float world -- you can use round(x, 2)
, but that will still give you a float, so it won't necessarily have "exactly 2 digits". Anyway, for a list of strings:
newlistofstrings = ['%.2f' % x for x in L1]
or for one with decimal numbers (which can have exactly 2 digits, if you want):
import decimal
newlistofnnumbers = [decimal.Decimal('%.2f') % x for x in L1]