In Python:
- If a line ends with a backslash, the current statement or expression is not terminated and instead carry on to the next line (i.e. an escaped linebreak does not affect parsing the way a regular linebreak does)
- Two adjacent string literals are concatenated (
"ab" "cd" == "abcd"
)
Combining these two properties allows you to span a single string literal over multiple lines, by closing a string literal using a quote, terminating the line with a backslash, then writing another string literal on the next line:
my_string = 'this is my string literal, ' \
'it continues on the next line'
>>> print my_string
"this is my string literal, it continues on the next line"
PyCharm detects you hitting Enter inside the string literal, and breaks the string literal for you. Try writing a single long string literal, then positioning the cursor somewhere in the middle of it and hitting Enter - PyCharm would split the string literal into two separate but adjacent string literals, on two different lines, with a backslash at the end of the first line.