New course! Every coder should learn Generative AI!
Try a free lesson0
How to make some arguments in __init__() default? If you write it like def __init__(self, color='red', legs) it returns error.
2 Answers
+ 5
You have to change the order of legs and color parameter in __init__ as default parameters should not be followed by non-default parameters.
And you have to change the order of the argument of the instantiation as well.
For example:
---> Cat("red", 4")
will be
---> Cat(4, "red")
https://code.sololearn.com/cA83a3A18A12
+ 1
default/optional arguments must come after required arguments:
def __init__(self,legs,color='red')