When I checked how to describe the concatenation of strings in multiple lines in Python, there were several patterns, so I tried to sort out the "good patterns" that can be used and the "bad patterns" that cause execution errors.
--String after \ [newline]
val = 'abcde' \
'12345678'
--String after + \ [newline]
val = 'abcde' + \
'12345678'
--Function after + \ [newline]
val = 'abcde' + \
str(12345678)
--The string +
function after + \ [newline]
val = 'abcde' + \
'1234' + str(5678)
--Separate with + [line feed]
and enclose in parentheses ()
.
val = ('abcde' +
'12345678')
#Indentation will also be available
val = (
'abcde' +
'12345678'
)
--Function after \ [newline]
val = 'abcde' \
str(12345678)
Execution results in SyntaxError.
{
"errorMessage": "Syntax error in module 'hoge': invalid syntax (hoge.py, line 2)",
"errorType": "Runtime.UserCodeSyntaxError",
"stackTrace": [
" File \"hoge.py\" Line 2\n str(12345678)\n"
]
}
that's all
Recommended Posts