I'm new to Python and I know you use "+" to concatenate strings like the following:
'foo' + 'bar'
Today I came across some code where it seems to concatenate strings using spaces(indentations) [Update: wrong example, see Edit 2 below]:
SQL = "select col1, col2 "
"from table"
I didn't find this feature got mentioned in the book I'm reading or anywhere on the web. Can someone please explain to me that:
- What does the space mean in this context? Why does it work?
- When would you prefer spaces over "+"? For readability when concatenating strings span multiple lines?
Edit: Thank you for all your responses. After trying the code out myself it indeed didn't work. I probably missed some details when looking at the code before I left for work; so I'll check it out tomorrow. However, the following did work (and this made me assume the SQL example works without verifying first):
x = "foo" "bar" # "foobar"
Edit 2: It turned out that I missed a pair of parentheses in the SQL example above. The actual code looks like this:
SQL = ("select col1, col2 "
"from table")