2nd Semester Intro to Computer Science

Do Now 7.02

In your Console

Type the following

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

my_pet = Pet("Peter")
print(my_pet.name)

In your Notebook

Respond to the following

  1. What is the purpose of the __init__ method?
  2. What if you wanted to initialize all pet objects with a name and a color?
  3. How would you modify the code to create a pet object with a name of “Peter” and a color of “brown”?

Edit this page Report an issue