Introduction to classes


#1



Traceback (most recent call last):
File "python", line 8, in
TypeError: init() takes exactly 2 arguments (3 given)


Replace this line with your code. 
class Animal(object):
    def __init__(self,name):
        self.name=name
        
    
    
    
zebra=Animal("zebra","Jeffrey")
print zebra.name


#2

Okay okay i understood..:slight_smile:


#3

I thought we have to pass the name of the object also..


#4

You should pass the name, "Jeffrey".
You got the error message that you did because self was already passed to any Animal animal object.
The __init__ shows that you need the two arguments self and name. self is automatically passed, so you just need to pass "Jeffrey" to the zebra object.

It would look like

zebra = Animal("Jeffrey") #spacing doesn't really matter regarding equal signs.

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.