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

I need an explanation for this one please.

I don't quite understand what an instance is. I watched the video like 5 times and I still don't get how to create one.

first_class.py
class Student:
    name = "darrin"

3 Answers

You got the first part right. Once you've created me though, you don't call the class again. It says "Then print() out the name attribute of your instance." Your instance is me. How would you print out its name? Remember, to get an object's attribute you can use the dot operator. Here's a full example:

# define the class
class Cat:
    sound = 'meow'
    legs = 4
    character = 'nice'

fluffy = Cat() # create an instance of the class
print(fluffy.sound) # prints 'meow'

He creates an instance of the Thief class when he does kenneth = Thief(). You call the class like it's a function and you can store that in a variable. An instance is a specific object of the type defined by the class.

So something like me = Student()

and then I print it calling the class like a function?