Skip to Content
Introduction to Classes
Instantiating Your First Object

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
  1. First we create a class named Square with an attribute sides.
  2. Outside the class definition, we create a new instance of Square named my_shape and access that attribute using my_shape.sides.



Outside the Animal class definition, create a variable named zebra and set it equal to Animal("Jeffrey").

Then print out zebra‘s name.

Folder Icon

Take this course for free

Already have an account?