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: 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 User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Subject: Re: Using + with strings considered bad References: <878udbxrpg.fsf@Equus.decebal.nl> In-Reply-To: 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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)