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 trialvand123
5,210 PointsHow do I access and print members in my instance?
I think I created my instance correctly.. not sure how to print out the name value though.
class Student:
name = 'John'
Student() = me
3 Answers
Steven Parker
231,248 PointsTo create an instance, the new instance name goes on the left of the assignment, and the class name followed by parentheses goes on the right.
Then to access a property, you can use the membership operator (.) between the instance and property names.
adrian miranda
13,561 PointsYou have a little mistake in what you are doing. You defined your class fine, but you are not creating the instance correctly.
It is true that calling Student()
will create an instance of your class. But how do you assign that to me
?
Think about it. If you wanted to set me equal to five, you would do: me = 5
So, if you want to set me equal to whatever was returned by Student()
, how would you do that?
Once me
is set correctly, where will the value of name be? It will be inside me, so me.name
Let us know if that isn't enough.
vand123
5,210 PointsThank you both I was able to spot my mistake!
Steven Parker
231,248 PointsGlad I could help, and happy holidays!