X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109 Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'exception,': 0.07; 'formatting': 0.07; 'python': 0.07; '%s"': 0.09; '3.x': 0.09; 'subject:string': 0.09; 'substituted': 0.09; 'throw': 0.09; 'pm,': 0.11; 'exception': 0.12; 'wrote:': 0.14; '*any*': 0.16; 'str()': 0.16; 'subject:formatting': 0.16; 'wanted.': 0.16; '{0}': 0.16; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'skip:{ 10': 0.23; 'possible,': 0.25; 'received:209.85.161.46': 0.26; 'received:mail-fx0-f46.google.com': 0.26; 'instead': 0.26; 'message-id:@mail.gmail.com': 0.28; '"the': 0.28; 'received:209.85.161': 0.29; 'fri,': 0.29; 'number,': 0.29; 'cc:addr:python.org': 0.31; 'construct': 0.31; 'kicks': 0.31; 'entry': 0.32; "skip:' 10": 0.32; "isn't": 0.34; 'clearly': 0.34; 'there': 0.35; 'that,': 0.35; 'should': 0.37; 'received:209.85': 0.37; 'exactly': 0.37; 'received:google.com': 0.38; 'but': 0.38; 'degree': 0.38; 'reasons': 0.38; 'used': 0.38; 'not,': 0.39; 'received:209': 0.39; 'header:Received:5': 0.40; '2011': 0.62; '(3)': 0.64; 'hand,': 0.72; 'print()': 0.84; 'so:': 0.84; 'to:addr:charter.net': 0.84; 'presumably': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=rG6DgN8zFnfDnBtsR1yfa6cjM/F6HXaK9Wl10rdJc7w=; b=Ra2Fi3+UB3zw6A89iSSdZgWqcCHQaI0Qbrx88Es2Kz3Flvra7AGR9tdgFiWejnRT5H YfdGAAU2xOXECL1eHYszwX2ECb0EPOZpVb9fnMSr4yWHiuoAJ3X6mZbr4kNSZXMWI9bo wIJgJzqDETFGKdQweFQkmdJ2/15/VNn/0gTvw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=smnCNrgya6VGeshIrrjcMiChwLg8So0JheNYLNJpBzUhZKcDstf19kRGnRcBtLLOfQ SLTM7q29S1+JFoDSzZSiB2fcWtws3WHK/JvXj9O9Iqun1F9R3yV401wah1sTbEy8aPC1 vgpRWS7aPA+Es06IuGwNymFyRDT9nYS6l+k4I= MIME-Version: 1.0 In-Reply-To: References: <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Fri, 6 May 2011 13:54:52 -0600 Subject: Re: string formatting To: harrismh777 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list 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: 34 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1304711724 news.xs4all.nl 81478 [::ffff:82.94.164.166]:55727 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4859 On Fri, May 6, 2011 at 1:39 PM, harrismh777 wrote= : > harrismh777 wrote: =A0 =A0OP wrote: > >> (1) "the %s is %s" % ('sky', 'blue') >> >> (2) "the {0} is {1}".format('sky', 'blue') >> >> (3) "the {} is {}".format('sky', 'blue') > > =A0 On the other hand, consider this 3.x code snip: > > =A0 print("the %s is %d" % ('sky', 'blue')) > > > =A0 That formatting will throw an exception, because the format construct= is > restricting the format entry to be a number, which 'blue' clearly isn't..= .. If you used %d, then that exception is presumably what you wanted. If not, then you should just do: print("the %s is %s" % ('sky', 'blue')) > =A0 The following print() is better, because *any* time or *most* types c= an be > substituted and the 'polymorphism' of Python kicks in allowing for that, = as > so: '%s' has exactly the same degree of polymorphism as '{}', because both simply call str() on their argument. There are good reasons to use format instead of % if possible, but polymorphism isn't one of them.