Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4837 > unrolled thread

Re: string formatting

Started byMRAB <python@mrabarnett.plus.com>
First post2011-05-06 15:58 +0100
Last post2011-05-06 15:58 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: string formatting MRAB <python@mrabarnett.plus.com> - 2011-05-06 15:58 +0100

#4837 — Re: string formatting

FromMRAB <python@mrabarnett.plus.com>
Date2011-05-06 15:58 +0100
SubjectRe: string formatting
Message-ID<mailman.1251.1304693968.9059.python-list@python.org>
On 06/05/2011 08:18, Jabba Laci wrote:
> 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?
>
I use Python 3, and I tend to use (3), unless I need to use the same
value more than once.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web