semi-concatenated strings

jodoin jodoin at cpsc.ucalgary.ca
Thu May 30 17:10:45 EDT 2002


Actually this is not an error in the Parser. It is well documented that you can
do this. In the grammar rules
a string can imediately follow another string.  This rule is specified so that
you will not have to use
as many backslashes. For more information see the Python Language Specification
in section 2.4.2 String Literal concatenation

Cheers,

Grant Griffin wrote:

> Hi Gang,
>
> I discovered today that strings can sometimes be concatenated without using a
> "+":
>
>    ActivePython 2.2.1 Build 222 (ActiveState Corp.) based on
>    Python 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32
>    Type "help", "copyright", "credits" or "license" for more information.
>    >>> a = 'one' ' plus ' 'two'
>    >>> a
>    'one plus two'
>
> I discovered this, of course, while making a mistake like this:
>
>    >>> a = ['zero', 'one'
>    ...       'two', 'three']
>    >>> a
>    ['zero', 'onetwo', 'three']
>
> (Note the missing comma after 'one'.)
>
> Is there some grand purpose here, or is this just a bug in the parser?
>
> errors-should-never-pass-silent-ly y'rs,
>
> =g2

--
Georges Jodoin
jodoin at cpsc.ucalgary.ca


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20020530/84132780/attachment.html>


More information about the Python-list mailing list