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


Groups > comp.lang.python > #89562

Re: Using + with strings considered bad

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <aberg010@my.HennepinTech.edu>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.081
X-Spam-Evidence '*H*': 0.84; '*S*': 0.01; 'subject: + ': 0.07; 'lawrence': 0.09; 'sentence': 0.09; 'strings.': 0.09; '"."': 0.16; 'nose': 0.16; 'readable': 0.16; 'such,': 0.16; 'write.': 0.16; 'wrote:': 0.18; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'lines': 0.31; 'received:10.0.0': 0.31; "skip:' 10": 0.31; 'subject:with': 0.35; 'but': 0.35; 'received:10.0': 0.36; 'so,': 0.37; 'received:10': 0.37; 'performance': 0.37; 'to:addr:python-list': 0.38; 'issue': 0.38; 'anything': 0.39; 'bad': 0.39; 'flow': 0.39; 'to:addr:python.org': 0.39; 'numbers': 0.61; 'simply': 0.61; "you're": 0.61; 'determine': 0.67; 'as:': 0.81; 'characters,': 0.84; 'subject:Using': 0.84; 'fibonacci': 0.91; 'fight': 0.97
Authentication-Results python.org; dkim=none (message not signed) header.d=none;
Date Wed, 29 Apr 2015 06:40:47 -0500
From Andrew Berg <aberg010@my.hennepintech.edu>
User-Agent Mozilla/5.0 (Windows NT 6.2; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version 1.0
To <python-list@python.org>
Subject Re: Using + with strings considered bad
References <878udbxrpg.fsf@Equus.decebal.nl> <mhq72r$jr9$1@ger.gmane.org>
In-Reply-To <mhq72r$jr9$1@ger.gmane.org>
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding 7bit
X-Originating-IP [73.5.142.244]
X-ClientProxiedBy CY1PR12CA0033.namprd12.prod.outlook.com (25.160.137.43) To CY1PR03MB1504.namprd03.prod.outlook.com (25.163.17.22)
X-Microsoft-Antispam UriScan:; BCL:0; PCL:0; RULEID:; SRVR:CY1PR03MB1504; UriScan:; BCL:0; PCL:0; RULEID:; SRVR:CY1PR03MB1389;
X-Microsoft-Antispam-PRVS <CY1PR03MB15040996F3467C4A82C04228DDD70@CY1PR03MB1504.namprd03.prod.outlook.com>
X-Exchange-Antispam-Report-Test UriScan:;
X-Exchange-Antispam-Report-CFA-Test BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:CY1PR03MB1504; BCL:0; PCL:0; RULEID:; SRVR:CY1PR03MB1504;
X-Forefront-PRVS 05610E64EE
X-Forefront-Antispam-Report SFV:NSPM; SFS:(10019020)(6009001)(6049001)(479174004)(24454002)(65956001)(46102003)(87976001)(66066001)(47776003)(40100003)(59896002)(86362001)(80316001)(54356999)(65816999)(42186005)(122386002)(88552001)(33656002)(450100001)(4001350100001)(110136001)(92566002)(2950100001)(77096005)(75432002)(77156002)(87266999)(65806001)(50986999)(76176999)(89122001)(83506001)(23676002)(2351001)(50466002)(107886001)(62966003)(64126003); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR03MB1504; H:[10.0.0.21]; FPR:; SPF:None; MLV:sfv; LANG:en;
X-MS-Exchange-CrossTenant-OriginalArrivalTime 29 Apr 2015 11:40:54.7072 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader Hosted
X-MS-Exchange-Transport-CrossTenantHeadersStamped CY1PR03MB1504
X-OriginatorOrg my.hennepintech.edu
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.89.1430331235.3680.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1430331235 news.xs4all.nl 2940 [2001:888:2000:d::a6]:34869
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:89562

Show key headers only | View raw


On 2015.04.29 04:08, Mark Lawrence wrote:
> On 29/04/2015 09:29, Cecil Westerhof wrote:
>> Because I try to keep my lines (well) below 80 characters, I use the
>> following:
>>      print('Calculating fibonacci and fibonacci_memoize once for ' +
>>            str(large_fibonacci) + ' to determine speed increase')
>>
>> But I was told that using + with strings was bad practice. Is this
>> true? If so, what is the better way to do this?
>>
> 
> It's not bad practice as such, it's simply that performance takes a nose 
> dive if you're contatenating large numbers of strings.  If performance 
> is an issue the recommended way is to write.
> 
> ' '.join(strings)
> 
I thought it was frowned upon because it's less readable for anything non-trivial.

hero1 = 'Batman'
hero2 = 'Robin'
villain = 'The Joker'
place = 'Gotham City'

sentence = hero1 + " and " + hero2 + " fight " + villain + " in " + place + "."
# doesn't flow as well as:
sentence = "{hero1} and {hero2} fight {villain} in {place}.".format(
		hero1=hero1,hero2=hero2,villain=villain,place=place)

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


Thread

Using + with strings considered bad Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 10:29 +0200
  Re: Using + with strings considered bad Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-04-29 10:08 +0100
  Re: Using + with strings considered bad Peter Otten <__peter__@web.de> - 2015-04-29 11:24 +0200
    Re: Using + with strings considered bad Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 13:17 +0200
    Re: Using + with strings considered bad Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 14:23 +0200
      Re: Using + with strings considered bad Chris Angelico <rosuav@gmail.com> - 2015-04-29 22:55 +1000
  Re: Using + with strings considered bad Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-29 23:15 +1000
    Re: Using + with strings considered bad wxjmfauth@gmail.com - 2015-04-29 08:16 -0700
  Re: Using + with strings considered bad Andrew Berg <aberg010@my.hennepintech.edu> - 2015-04-29 06:40 -0500

csiph-web