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: 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 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: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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.