please can someone tell me the difference between the two | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

please can someone tell me the difference between the two

class Person: def __init__(self, name): self.name = name class Person: def __init__(self): self.name = "John"

13th Sep 2019, 3:00 PM
Sarfo Agyemang
Sarfo Agyemang - avatar
1 Answer
+ 1
The diffrence is that the first constructor get a parameter called "name" and then you initiallize the name attribute with what parameter the user input. The second one don't have parameter in the constructor so, when the user create a object from this class and don't enter a parameter, the second constructor will be called and the name will initiallize to "John".
13th Sep 2019, 3:15 PM
KfirWe
KfirWe - avatar