Unexpected string behaviour: txt = 'this' ' works'

Quentin Gallet-Gilles qgallet at gmail.com
Wed Feb 11 06:21:29 EST 2009


*Literal* string concatenation has always been a part of Python :
http://docs.python.org/reference/lexical_analysis.html#string-literal-concatenation


On Wed, Feb 11, 2009 at 12:06 PM, c d saunter <
christopher.saunter at durham.ac.uk> wrote:

> I did a double take when debugging an error the other day.  My
> problem was missing out a comma when building a list of strings.
>
> Much to my surprise the offending code still executed to cause
> problems later on:
>
> >>> txt = 'this', 'works'
> >>> print txt
> ('this', 'works')
> # As expected
> >>> txt = 'this' 'works'
> >>> print txt
> thisworks
> # Eh?
>
> I have never seen this behaviour before, but it works in Python 2.2.1
> and 2.5.4 so I guess it's meant to be there.  I assume it is a feature
> of the compiler.
>
> Any thoughts?
> Regards
> Chris
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090211/6d6e5db5/attachment.html>


More information about the Python-list mailing list