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 Instant Objects Your first class

Need help

What am i doing wrong with this code?

first_class.py
class Student:
    name="Emily"
    def name(self):
        return self.name
me=NewClass()
me.Student()

1 Answer

Renato Guzman
Renato Guzman
51,436 Points

Hi Emily!

It is not required that you define a method for name. The first two lines are enough for the class Student, since you are declaring an attribute with your name and it is stored in the class already.

Then you are instantiating the class NewClass which is not defined and that will throw an error. The instance should be just Student() and be assigned to the variable me.

Then the me variable will have all the attributes of the class which is Student, and then you can print the name by just accessing the attribute with the dot: print(me....)