This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: String literals next to each other does not cause error
Type: behavior Stage: resolved
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Mariatta, Sam Lobel2, vaultah
Priority: normal Keywords:

Created on 2017-10-30 21:30 by Sam Lobel2, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg305252 - (view) Author: Sam Lobel (Sam Lobel2) Date: 2017-10-30 21:30
This seems too obvious to have been missed, but also too strange behaviour to be on purpose.

The following works for some reason (note there's no + between the words)
>>> variable = "first" "second"
>>> print(variable)
"firstsecond"

In a file, if you're missing a comma between two string literals, it combines them into one string (instead of throwing a syntax error). E.G:

>>> a = ["first",
... "second"
... "third"]
>>> print(a)
["first" "secondthird"]

BUT, the same thing with variables (thankfully) does not work.
>>> a = "first"
>>> b = "second"
>>> c = a b
Throws a syntax error.

The same sort of thing also breaks for integers.
>>> a = 4 7
throws a syntax error.

This just seems wrong to me. Is it? Has this been discussed a million times before?
msg305255 - (view) Author: Dmitry Kazakov (vaultah) * Date: 2017-10-30 21:49
This is a documented feature: https://docs.python.org/3/reference/lexical_analysis.html#string-literal-concatenation

And yes, it was discussed before: https://mail.python.org/pipermail/python-ideas/2013-May/020527.html
msg305256 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-10-30 21:51
What Dmitry said :) I'm closing this as "not a bug".
History
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 76087
2017-10-30 21:51:16Mariattasetstatus: open -> closed

versions: - Python 2.7, Python 3.4, Python 3.5, Python 3.6
nosy: + Mariatta

messages: + msg305256
resolution: not a bug
stage: resolved
2017-10-30 21:49:03vaultahsetnosy: + vaultah
messages: + msg305255
2017-10-30 21:35:56Sam Lobel2settype: behavior
2017-10-30 21:30:45Sam Lobel2create