Python Object-Oriented Python Dice Roller Giving a Hand

Jonathan Gonzalez
Jonathan Gonzalez
4,823 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
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher


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

class Dog:

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

for i in range(10):

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
4,823 Points

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