Jim Mahoney
Jim Mahoney

Reputation: 48

String concatenation without + (just space or adjacent strings) in Python 2.7.5?

Can anyone explain why this isn't just a syntax error?

$ python --version
Python 2.7.5
$ python
>>> 'a' + 'b'                # string concatenation, as expected
'ab'
>>> 'a' 'b'                  # still string concatenation ?
'ab'
>>> "a"'b'                   # or even this ...
'ab'
>>> ""''""''""''""''""''""   # or this !?
''

I've googled and searched the python docs but haven't found anything related. Just a bug?

Upvotes: 0

Views: 239

Answers (1)

BrenBarn
BrenBarn

Reputation: 251608

Adjacent string literals are combined into one at the parsing stage. This is documented here.

Upvotes: 3

Related Questions