How can I do a line break (line continuation) in Python?
In Python, you can use the "\" character to indicate a line continuation. For example:
You can also use parentheses, brackets, or braces to indicate a line continuation. For example:
x = (1 + 2 + 3 +
4 + 5 + 6)
y = [1, 2, 3,
4, 5, 6]
z = {1: "one",
2: "two"}
print(x)
print(y)
print(z)
Watch a video course
Python - The Practical Guide
Another way is to use an explicit line joining operator (;
)
You can also use triple quotes """
or '''