Instantiating your first object


#1

This is the code I have written:
class Animal(object):
def init(self, name):
self.name = name

      zebra = Animal("Jeffrey")
      print zebra.name

bur anytime I press save and continue, it keeps giving error asking if have declared a variable called zebra.
Please help me check where have been making a mistake.
This is the task for that section:

Outside the Animal class definition, create a variable named zebra and set it equal to Animal("Jeffrey").
Then print out zebra's name.
Thanks


#2

Be sure not to indent the last two lines.

class Animal(object):
    def __init__(self, name):
        self.name = name

zebra = Animal("Jeffrey")
print zebra.name

#3

Make sure you set your member variable. Like this:

def init(self, name):
self.name = name

Also, to elaborate on what mtf said. Your instance and print command need to be outside the init method. If they are not, they will be considered a part of the function and not a declared variable.