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
sradms0
Treehouse Project ReviewerExplanation for attributes and instances?
Could someone provide some info on these? I have an idea, but I want to make sure I fully understand the concept of both. Thanks for your help
2 Answers
Ken Alger
Treehouse TeacherScott;
I'm not sure I fully understand what information you are wanting, but I'll give it a go, at least as it pertains to my understanding of Python Classes, okay?
Class attributes apply to every object that is a type of that class. Instance attributes apply to specific instances of that class.
For example, if we had a class Dog we could assign a class attribute to it of sound = "bark". Now, every Dog would bark. If we created a specific dog, say for a very large, mean dog, we could change the attribute for that instance to "growl". So something like:
class Dog:
sound = "bark"
If we check Dog.sound it would give us "bark", right? What if we did meanDog = Dog()? By default it's attribute would be "bark" as well. We can change it's instance attribute with meanDog.sound = "growl".
Does that make any sense or is that even what your question was?
Post back either way.
Happy coding,
Ken
sradms0
Treehouse Project ReviewerThis is exactly what I wanted. I understand now. Thanks, Ken.