python - Format list of tuples to 1 decimal -
how format number have 1 decimal place? have 4 numbers want add tuple, each having 1 decimal place. tried messing around .format couldn't seem work tuple.
a = 1 b = 2 c = 3 d = 4.44 my_tup = (a,b,c,d)
and want my_tup formatted so. (1.0, 2.0, 3.0, 4,4)
thanks help!
a, b, c, d = 1, 2, 3, 4.44 my_tup = (a, b, c, d) my_tup = tuple([float("{0:.1f}".format(n)) n in my_tup])
however, tuple
immutable sequence can't change after have created it. it's better have numbers formatted correctly before put them in tuple; avoid whole (ugly) create list
create tuple
in tuple([float("{0:.1f}".format(n)) n in my_tup])
Comments
Post a Comment