Using + with strings considered bad

Cecil Westerhof Cecil at decebal.nl
Wed Apr 29 13:17:17 CEST 2015


Op Wednesday 29 Apr 2015 11:24 CEST schreef Peter Otten:

> 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? 

[...]

>> print('Calculating fibonacci and fibonacci_memoize once for ' +
>> str(large_fibonacci) + ' to determine speed increase')
>
> You could write that as
>
> print('Calculating fibonacci and fibonacci_memoize once for '
> '{} to determine speed increase'.format(large_fibonacci))
>
> but in a simple case like yours I'd go with the obvious
>
> print(
> 'Calculating fibonacci and fibonacci_memoize once for',
> large_fibonacci,
> 'to determine speed increase')

I have gone for this option. Thanks.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof



More information about the Python-list mailing list