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


Groups > comp.lang.python > #4802

string formatting

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <jabba.laci@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.020
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'python': 0.07; '%s"': 0.09; 'subject:string': 0.09; 'to:name:python mailing list': 0.09; 'subject:formatting': 0.16; '{0}': 0.16; 'skip:{ 10': 0.23; 'preferred': 0.26; 'message-id:@mail.gmail.com': 0.28; '"the': 0.28; 'string': 0.29; 'hi,': 0.29; 'received:209.85.210.46': 0.31; 'received:mail-pz0-f46.google.com': 0.31; 'style.': 0.31; 'to:addr :python-list': 0.32; 'should': 0.37; 'received:209.85': 0.37; 'received:google.com': 0.38; 'but': 0.38; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'header:Received:5': 0.40; '(3)': 0.64
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:from:date:message-id:subject:to :content-type; bh=H5HSb6t2voc+ZDzqCJqwM3pccB8Z1W7/NZUZrwP/SCM=; b=wPiV/iIth2UHdozmeF0SwdTmigMiMqVAFDNj2+1B4+Yp+bi9bm32laLySoFunQMVGR u9dwpLCD8zXn4KGsDkIFN1dJp5ECpIiXc5yX0XrS/kVUbGjrxRvHB+hiXQ53loAJCLl8 VieqfzCpDPOvZm8xK+vKq3vOObWtXlfq0XzOY=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=Q0OCYBs4ydYuy3+4ILHyW38wEgB0GVzl7g8JsTS4wZ1NiRb2+Li/1PRCemZAA1ARYM FAQZTjtiGmnHtxoqXtGiWw6fvLMm+GWyihtrbC9ecurWKDAHH9r7mkKZa6MzA/XAGcSO MnHMUxDR3Mp/HZ+6/BXs83smwoLAllnVSKAXI=
MIME-Version 1.0
From Jabba Laci <jabba.laci@gmail.com>
Date Fri, 6 May 2011 03:18:17 -0400
Subject string formatting
To Python mailing list <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1229.1304666321.9059.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 82.94.164.166
X-Trace 1304666321 news.xs4all.nl 34849 [::ffff:82.94.164.166]:60588
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:4802

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

string formatting Jabba Laci <jabba.laci@gmail.com> - 2011-05-06 03:18 -0400
  Re: string formatting Web Dreamer <webdreamer@nospam.fr> - 2011-05-06 10:00 +0200
    Re: string formatting Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-06 08:46 +0000
      Re: string formatting Chris Rebert <clp2@rebertia.com> - 2011-05-06 02:23 -0700
        Re: string formatting Web Dreamer <webdreamer@nospam.fr> - 2011-05-06 14:10 +0200
          Re: string formatting nn <pruebauno@latinmail.com> - 2011-05-06 06:06 -0700
          Re: string formatting Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-06 14:33 +0000
          Re: string formatting Web Dreamer <webdreamer@nospam.fr> - 2011-05-10 16:15 +0200
            Re: string formatting Chris Angelico <rosuav@gmail.com> - 2011-05-11 00:43 +1000
        Re: string formatting Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-06 14:24 +0000
          Re: string formatting harrismh777 <harrismh777@charter.net> - 2011-05-06 14:22 -0500
            Re: string formatting harrismh777 <harrismh777@charter.net> - 2011-05-06 14:39 -0500
              Re: string formatting Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-06 13:54 -0600
              Re: string formatting Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-07 02:30 +0000
              Re: string formatting alex23 <wuwei23@gmail.com> - 2011-05-08 22:47 -0700
            Re: string formatting Neil Cerutti <neilc@norwich.edu> - 2011-05-06 19:54 +0000
            Re: string formatting Terry Reedy <tjreedy@udel.edu> - 2011-05-06 16:54 -0400
            Re: string formatting Chris Angelico <rosuav@gmail.com> - 2011-05-07 10:09 +1000
            Re: string formatting Terry Reedy <tjreedy@udel.edu> - 2011-05-07 03:55 -0400
  Re: string formatting Raymond Hettinger <python@rcn.com> - 2011-05-10 10:20 -0700

csiph-web