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

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -