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


Groups > comp.lang.python > #3513

Re: [Tutor] working with strings in python3

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!post.news.xs4all.nl!not-for-mail
Return-Path <prologic@shortcircuit.net.au>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:: [': 0.03; '%s"': 0.09; 'subject:Tutor': 0.09; 'to:name:python list': 0.09; 'this:': 0.11; 'am,': 0.14; 'wrote:': 0.14; '"%s': 0.16; '10:17': 0.16; 'specifier': 0.16; 'subject:] ': 0.16; 'tue,': 0.20; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'message-id:@mail.gmail.com': 0.28; 'hall': 0.29; 'solved': 0.31; 'strings.': 0.31; 'subject:working': 0.31; 'to:addr:python-list': 0.32; 'normally': 0.35; 'considered': 0.36; 'subject:with': 0.37; 'apr': 0.38; 'received:google.com': 0.38; 'code:': 0.38; 'end': 0.39; 'to:addr:python.org': 0.39; "it's": 0.40; 'header:Received:5': 0.40; '2011': 0.62; 'received:74.125.83': 0.69; 'concatenate': 0.84
MIME-Version 1.0
In-Reply-To <BANLkTik3h6PP=3zenu+Deo+MAMN3jUTtxg@mail.gmail.com>
References <BANLkTik3h6PP=3zenu+Deo+MAMN3jUTtxg@mail.gmail.com>
From James Mills <prologic@shortcircuit.net.au>
Date Tue, 19 Apr 2011 10:34:27 +1000
Subject Re: [Tutor] working with strings in python3
To python list <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
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.531.1303173290.9059.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 82.94.164.166
X-Trace 1303173290 news.xs4all.nl 81485 [::ffff:82.94.164.166]:39309
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:3513

Show key headers only | View raw


On Tue, Apr 19, 2011 at 10:17 AM, Rance Hall <ranceh@gmail.com> wrote:
> pseudo code:
>
>
> message = "Bah."
>
> if test:
>   message = message + " Humbug!"
>
> print(message)
>
> end pseudo code

Normally it's considered bad practise to concatenate strings.
Use a a format specifier like this:

> message = "Bah."
>
> if test:
>   message = "%s %s" (message, " Humbug!")
>
> print(message)

Python3 (afaik) also introduced the .format(...) method on strings.

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"

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


Thread

Re: [Tutor] working with strings in python3 James Mills <prologic@shortcircuit.net.au> - 2011-04-19 10:34 +1000
  Re: [Tutor] working with strings in python3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-19 02:16 +0000
    Re: [Tutor] working with strings in python3 Chris Angelico <rosuav@gmail.com> - 2011-04-19 13:22 +1000
    Re: [Tutor] working with strings in python3 Westley Martínez <anikom15@gmail.com> - 2011-04-18 20:26 -0700

csiph-web