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 trialJonathan Gonzalez
8,544 PointsDo 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
Treehouse TeacherHi!
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
8,544 PointsJonathan Gonzalez
8,544 PointsOk, I got it, instances don't have to be assigned to variables.
Thanks!