Hy there,
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:
class person:
def _init_(self, firstName, lastName):
self.firstName = firstName
self.lastName = lastName
def fullName(self):
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
Alternatively:
>>> Maria = person()
>>> Maria.fullName()
AttributeError: person instance has no attribute 'firstname'
What can I do to fix this problem?
Thanks for your help.
Enry
'Maria Smith'
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:
class person:
def _init_(self, firstName, lastName):
self.firstName = firstName
self.lastName = lastName
def fullName(self):
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
Alternatively:
>>> Maria = person()
>>> Maria.fullName()
AttributeError: person instance has no attribute 'firstname'
What can I do to fix this problem?
Thanks for your help.
Enry
'Maria Smith'