I have defined a function with a long list of arguments. The total characters in definition is above 80 and doesn't abide by PEP8.
def my_function(argument_one, argument_two, argument_three, argument_four, argument_five):
What can be the best approach to avoid horizontal scrolling?
There are two techniques that can be used to reduce a functions' arguments. One of them is to refactor the function, making it smaller, consequently, reducing the arguments' number. The Extract Method technique can be use to achieve this goal.
Except for functions with variable-length argument lists, the number of arguments in a function call must be the same as the number of parameters in the function definition. This number can be zero. The maximum number of arguments (and corresponding parameters) is 253 for a single function.
More than two arguments and statements can be used in a function.
In mathematics, an argument of a function is a value provided to obtain the function's result. It is also called an independent variable. , is called a unary function. A function of two or more variables is considered to have a domain consisting of ordered pairs or tuples of argument values.
An example is given in PEP 8:
class Rectangle(Blob): def __init__(self, width, height, color='black', emphasis=None, highlight=0):
So that is the official answer. Personally I detest this approach, in which continuation lines have leading whitespace that doesn't correspond to any real indentation level. My approach would be:
class Rectangle(Blob): def __init__( self, width, height, color='black', emphasis=None, highlight=0 ):
. . . or just let the line run over 80 characters.
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