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

Making an instance of a class

It asks me to make an instance of a class named me but I do not understand what it means. It also ask me to then print()

first_class.py
class Student:
    name = "Noah"
    Noah = Student()

I'm sorry for asking for help I'm still new to coding.

5 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 Points

You are pretty close to the correct answer! You understood the first part and got that correct -- nice job -- let's build on that.

Part 2 of the challenge wants you to "instantiate" an object named "me" that uses the Student class from part 1. A class is sort of like a factory or template for creating new student objects. The "instantiate" part means to create a new Student object that uses the class (or factory template) to create a new object named "me". Then finally show that you can print out its attribute "name". See below where I break this down.

Good luck with your Python journey!

# Part 1, create a class named Student and give it an attribute "name" which contains anything you choose.

class Student:
    name = "Noah"

# Part 2, create an "instance" of the class named me and print out the name attribute

me = Student()
print(me.name)

I did as you said and the only thing that didn't work is that it says can't find student. Also' when I write print(me.name) the word print is yellow and not blue.

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 Points

Yes-- this is a good learning moment! If you don't include the class declaration (from the first part), the second part (instantiation) won't know what "Student" is. In short, the Code Challenge needs BOTH of the parts to work properly.

# declaration of the Student class
class Student:
    name = "Noah"

# instantiation of "me" object which is a "Student
me = Student()
# finally, print it out.
print(me.name)

I don't understand what you mean by finally printing it out I don't know if I'm doing something wrong but this is what I wrote. class Student: name = "Noah" me = Student() print(me.name)

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 Points

You should re-try the code challenge-- You will see that the last item asked for was to print out the name attribute of the me object.

ThatOneCoder -
ThatOneCoder -
9,310 Points

class Student():

name = 'name'

me = Student()

print(me.name)

Well this is my answer. You could have a Indentation mistake??

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 Points

Sorry, I missed that you asked another question in this thread. I hope you figured it out on your own. The indentation for the class declaration is required.

class Student:
    name = 'name';