Using + with strings considered bad

Cecil Westerhof Cecil at decebal.nl
Wed Apr 29 14:23:36 CEST 2015


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

>> 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')

In 2.7 that gives:
   ('Calculating fibonacci and fibonacci_memoize once for', 40, 'to determine speed increase')

So I am going to use the one above it.

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



More information about the Python-list mailing list