Learn
Perfect! Now we’re ready to start creating objects.
We can access attributes of our objects using dot notation. Here’s how it works:
class Square(object): def __init__(self): self.sides = 4 my_shape = Square() print my_shape.sides
- First we create a class named
Square
with an attributesides
. - Outside the class definition, we create a new instance of
Square
namedmy_shape
and access that attribute usingmy_shape.sides
.
Instructions
1.
Outside the Animal
class definition, create a variable named zebra
and set it equal to Animal("Jeffrey")
.
Then print
out zebra
‘s name.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.