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

Help with Object-Oriented Python challenge task 2

It says to make an instance of your class named me and then print() out the name attribute of your instance. I am honestly not sure what to do. Please help.

Thank you in advance

first_class.py
class Student:
    name = "AA"
    me = Student()
    print(name)

1 Answer

first, we don't create an instance of the class inside the class second, make sure you use the name of your instance to get to the name attribute.

here you go:

class Student:
    name = "AA"


me = Student()
print(me.name)

Great thank you so much! I figured it out now.

Manuel Canario
Manuel Canario
1,458 Points

Can someone explain besides that the challenge ask to create me = Student() what is the purpose of making a second connection name.student vs me.name do I need to assign a variable to the class & attribute to be able to use it??

In the example, you have the class 'Student', which represents the methods and attributes of any object that will be an instance of it. so, the object 'me' is an instance of the 'Student' class, then for sure 'me' has an attribute called 'name'. I hope this is the answer you're looking for.