How do you break a long single-line method call to multiple lines?

Experience Level: Junior
Tags: Python

Answer

When calling a method, the arguments can be broken to multiple lines because they are between brackets.

Example:

def do_something(name: str, age: int, nick: str):
  print(f"{name} {age} {nick}")

do_something(
    name="John Doe",
    age=78,
    nick="Frog")

Python for beginners
Python for beginners

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

Test yourself