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

Mikkel Bielefeldt
Mikkel Bielefeldt
3,227 Points

first_class.py

I'm just lost here I've tried a little bit of everything, and rewatched Kenneth's video multiple times, but just cant seem to figure it out. I should probably add that quiz or test number one wasn't a problem it's number two where I just fall apart.

first_class.py
class Student:
    name = "Mikkel Bielefeldt"

2 Answers

You could check the Python docs. There you will find:

Class instantiation uses function notation. Just pretend that the class object is a parameterless function that returns a new instance of the class. For example (assuming the above class):

x = MyClass()

Mikkel Bielefeldt
Mikkel Bielefeldt
3,227 Points

Hi Kris Nikolaisen. I’ve been sitting at this problem for quite awhile and I just don’t get it can you go in more depth or just give me the answer and then I’ll review it and try my own things.

The second task is to create an instance of your class named me. Following the syntax above:

me = Student()

Then print the name attribute of the instance.

print(me.name)

This should print "Mikkel Bielefeldt"