Imagine this:
def method(self, alpha, beta, gamma, delta, epsilon, zeta, eta, theta, iota, kappa):
pass
The line overpass the 79 characters, so, what's the pythonic way to multiline it?
The * symbol is used to pass a variable number of arguments to a function. Typically, this syntax is used to avoid the code failing when we don't know how many arguments will be sent to the function.
Luckily, you can write functions that take in more than one parameter by defining as many parameters as needed, for example: def function_name(data_1, data_2):
Many times, we tend to add too many parameters to a function. But that's not the best idea: on the contrary, when a function requires too many arguments, grouping them into coherent objects helps writing simpler code.
You can include line breaks within parentheses (or brackets), e.g.
def method(self, alpha, beta, gamma, delta, epsilon, zeta,
eta, theta, iota, kappa):
pass
(the amount of whitespace to include is, of course, up to you)
But in this case, you could also consider
def method(self, *args):
pass
and/or
def method(self, **kwargs):
pass
depending on how you use the arguments (and how you want the function to be called).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With