string formatting

Jabba Laci jabba.laci at gmail.com
Fri May 6 03:18:17 EDT 2011


Hi,

Which is the preferred way of string formatting?

(1) "the %s is %s" % ('sky', 'blue')

(2) "the {0} is {1}".format('sky', 'blue')

(3) "the {} is {}".format('sky', 'blue')

As I know (1) is old style. (2) and (3) are new but (3) is only
supported from Python 2.7+.

Which one should be used?

Laszlo



More information about the Python-list mailing list