When coding in Python, I found that defining a list of strings without separating the strings with a comma is not a syntax error. When running this code:
x = ['a', 'b', 'c'] # this is the proper one
y = ['a' 'b' 'c'] # commas missing!
print(x) # results in ['a', 'b', 'c']
print(y) # results in ['abc']
However, if I run this code, Python complains about it.
a = 'a'
b = 'b'
c = 'c'
z = [a b c] # SyntaxError: invalid syntax. Perhaps you forgot a comma?
Instead of reporting an error, Python simply assumes that the three non-comma-separated strings should be combined into the same string. What are the reasons for this? Is it common for people to write lists of strings without comma separators and intend for them to be the same string?
"a" "b"
being treated like"a" + "b"
rather than as a syntax error, as it would lead to undetectable typos and bugs. ¶ Over the years since then I've encountered more than a few instances of arrays of strings, one per line, being reordered leaving the string from the last line (no comma at the end) somewhere in the middle and silently concatenated to the following element. It's very difficult to notice (until things break weeks, months, or years later). I don't know why Python copied such a bad idea. $\endgroup$