Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python Dice Roller Giving a Hand

Jonathan Gonzalez
Jonathan Gonzalez
8,544 Points

Do the instances of D6 have names?

From what I understand, by running the for loop in the Hand class, we created 5 instances of the D6 class and added them to our list(yh), which is an instance of the Hand class. Do those instances of the D6 class have names and if so, how are they generated?

1 Answer

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Hi!

Class instances only have names if you set them equal to a variable. For instance:

class Dog:
    pass

If I have a class called Dog and I create a bunch of instances using a for loop:

for i in range(10):
    Dog()

These instances don't have a specific name, they are just instances. I can, however, set instances equal to a variable like this:

my_dog = Dog()
your_dog = Dog()
# etc...

Then these instances have variables names to go with them.

Jonathan Gonzalez
Jonathan Gonzalez
8,544 Points

Ok, I got it, instances don't have to be assigned to variables.

Thanks!