Introduction to Computing
Multiline Statements in Python Source Code
We can use the backslash \
symbol as the last character of any line to split long lines of statements into multiple lines for better readability. All those lines are part of a single statement. Be careful that there must be no space characters after the \
.
print("This statement has a long text string to be printed on the output terminal.")
The following code has the similar output and \
symbol can be used as many times as necessary to make the code more readable.
print("This statement has a long text string to be \
printed on the output terminal.")
a = 300 * 4 / (240 + 56) * 25 + 100 \
/ 2 + 4 / 6
print (a)