How to make some arguments in __init__() default? If you write it like def __init__(self, color='red', legs) it returns error. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to make some arguments in __init__() default? If you write it like def __init__(self, color='red', legs) it returns error.

https://code.sololearn.com/c4oxCAW3jI0r/?ref=app

25th Jan 2021, 4:58 AM
Alexander Grothendieck
Alexander Grothendieck - avatar
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
25th Jan 2021, 5:07 AM
noteve
noteve - avatar
+ 1
default/optional arguments must come after required arguments: def __init__(self,legs,color='red')
25th Jan 2021, 5:08 AM
visph
visph - avatar