I recently stumbled across a problem in Python 2.7.9. I defined a list of strings, but I forgot to set a comma on one item like this:
myList = ["a", "b", "c" "d"]
which results in this list:
["a", "b", "cd"]
I guessed that Python effectively inserted a +
operator and was curious what would happen in similar cases, e.g.:
[1,2,3 4]
but Python just tells me that this is invalid syntax (as I expected for the first case, too).
So why does Python concatenate strings if NO operator is defined between them? Is there a good use case, where omitting the +
operator has benefits?