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

Popular posts from this blog

python - How to add an model instance to a django queryset? -

Using Android Volley to post an array to PHP -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -