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 trialMiranda Chen
6,945 PointsHelp 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
class Student:
name = "AA"
me = Student()
print(name)
1 Answer
Mehdi SEHLOULI
21,801 Pointsfirst, 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)
Miranda Chen
6,945 PointsMiranda Chen
6,945 PointsGreat thank you so much! I figured it out now.
Manuel Canario
1,458 PointsManuel Canario
1,458 PointsCan 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??
Mehdi SEHLOULI
21,801 PointsMehdi SEHLOULI
21,801 PointsIn 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.