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 __init__

Not understanding the question

I don't know what's wrong it just keeps saying 'try again'

student.py
class Student:
  name = 'edward'

  def __init__(self, name):
    self.name = 'eddy'

1 Answer

Simon Merrick
Simon Merrick
18,305 Points

You haven't stated what the question actually is, though i think you are running into issues because of the way you have declared your variables.

The python documentation uses this example to show how to declare both class and instance variables

class Dog:
    kind = 'canine'                    # class variable shared by all instances
    def __init__(self, name):
        self.name = name           # instance variable unique to each instance

In your example you are setting self.name to 'eddy' every time. If you want to set the name variable for each instance you need something like this

class Student:
  def __init__(self, name):
    self.name = name

# Then you can create a new instance of Student, named Eddy, like this
# student = Student('Eddy')
# print(student.name)
# >> Eddy