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


Groups > comp.lang.python > #4837

Re: string formatting

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python': 0.07; '%s"': 0.09; 'from:addr:python': 0.09; 'subject:string': 0.09; 'wrote:': 0.14; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr :python-list': 0.16; 'subject:formatting': 0.16; '{0}': 0.16; 'tend': 0.16; 'header:In-Reply-To:1': 0.22; 'once.': 0.23; 'skip:{ 10': 0.23; 'received:84': 0.25; 'preferred': 0.26; '"the': 0.28; 'string': 0.29; 'hi,': 0.29; 'style.': 0.31; 'to:addr:python- list': 0.32; 'header:User-Agent:1': 0.35; 'reply- to:addr:python.org': 0.35; 'should': 0.37; 'but': 0.38; 'unless': 0.38; 'to:addr:python.org': 0.39; '(3)': 0.64; 'reply-to:no real name:2**0': 0.72; 'header:Reply-To:1': 0.72
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result At0HAN8LxE1UXebj/2dsb2JhbACYXY1md8UEhgkEk3yKMQ
Date Fri, 06 May 2011 15:58:19 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
MIME-Version 1.0
To python-list@python.org
Subject Re: string formatting
References <BANLkTi=66aSQ25Td5Gofef2mmwFottdfRg@mail.gmail.com>
In-Reply-To <BANLkTi=66aSQ25Td5Gofef2mmwFottdfRg@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
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.1251.1304693968.9059.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 82.94.164.166
X-Trace 1304693969 news.xs4all.nl 81479 [::ffff:82.94.164.166]:60715
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:4837

Show key headers only | View raw


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.

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


Thread

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

csiph-web