How do you split long method signature to multiple lines in the most efficient way?

Experience Level: Junior
Tags: Python

Answer

To break a long line to multiple lines, use a backslash character at the end of a line. However, when you need to break a long line with strings between brackets, you can break the line without using the backslash character

Example:

def do_something():
    message = "This is" \
                       "multi-line" \
                       "message that needs backslashes" \
                       "because we are not between brackets"

def do_something_else(
    something: str,
    number: int,
    message: str):
    print(message)

# In the method above, parameters are wrapped
# to new lines without using the backslash character.
# This is possible because the parameters are between
# brackets.

Python for beginners
Python for beginners

Are you learning Python ? Try our test we designed to help you progress faster.

Test yourself

Chat

Oh, the operator is not available. Leave us your comments. We will answer all your questions as soon as possible.

Comments

Anonymous
Καλησπέρα.
Anonymous
the infinteis -3/15 so 1triition / infinet
Anonymous
e
Anonymous
<a href="https://inspirum.pl "
Anonymous
[url]https://inspirum.pl[/url]
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e