implicitly concats of adjacent strings does not work with format

Cecil Westerhof Cecil at decebal.nl
Wed Apr 29 14:42:16 CEST 2015


I have the folowing print statements:
    print(
        'Calculating fibonacci_old, fibonacci_memoize and '
        'fibonacci_memoize once for {0} '.format(large_fibonacci))


    print(
        'Calculating fibonacci_old, fibonacci_memoize and '
        'fibonacci_memoize once for {0} '.format(large_fibonacci) +
        'to determine speed increase')

    print(
        'Calculating fibonacci_old, fibonacci_memoize and '
        'to determine speed increase'
        'fibonacci_memoize once for {0} '.format(large_fibonacci))


    print(
        'Calculating fibonacci_old, fibonacci_memoize and '
        'fibonacci_memoize once for {0} '.format(large_fibonacci)
        'to determine speed increase')

The first three work, but the last gives:
        'to determine speed increase')
                                    ^
    SyntaxError: invalid syntax

Not very important, because I can use the second one, but I was just
wondering why it goes wrong.

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



More information about the Python-list mailing list