Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
cannot initialise class with _init_ method
I have tried to create a Class using the method _init_ to initialise new instances.
When I create the object and pass the arguments, I get the TypeError:
the constructor takes no argument.
If I don't pass arguments, the object is created with no error. However when I call a method of the object, I get the AttributeError: the instance has no attribute 'name of attribute'
Here is the code I used to create the class:
def _init_(self, firstName, lastName):
self.firstName = firstName
self.lastName = lastName
return self.firstName + ' ' + self.lastName
Here is the code I run to create the object and print it:
>>> Maria = person('Maria', 'Smith')
TypeError: this constructor takes no arguments
>>> Maria = person()
AttributeError: person instance has no attribute 'firstname'
What can I do to fix this problem?
Thanks for your help.
0 · ·