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?