Python format output in concise manner -
Python format output in concise manner -
is there conciser way express:
'{:f};{:f};{:f};{:f};{:f}'.format(3.14, 1.14, 2.14, 5.61, 9.80) such 1 not need write{:f} multiple times?
you utilize nice way can think of generate string, illustration using join:
';'.join(['{:f}' _ in range(5)]).format(3.14, 1.14, 2.14, 5.61, 9.80) here's variation format within list comprehension. nice because doesn't require typing length of list.
nums = [3.14, 1.14, 2.14, 5.61, 9.80] ';'.join(['{:f}'.format(n) n in nums]) python
Comments
Post a Comment