Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python (retired) Objects Create a Class with a Method

Did you define the `hours` method?

That is what it keeps telling, what's wrong with the code.

method.py
class Store():
  open = 9
  close = 7

def hours():
  return print("We're open form {} to {}".format(open, close))

1 Answer

Dan Johnson
Dan Johnson
40,533 Points

In order to associate a method with a class it needs to be indented, like you do when associating code with a function definition. You also need to pass each method a special argument called self. self represents an instance of the class and you'll use it to access methods and properties, like open and close in this case.