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 Inheritance Complex Relationships

Ingrid Matthews
Ingrid Matthews
1,465 Points

attributes set within init

I've watched this video (and the next one) several times and several things are unclear to me. First, what is the difference between an attribute set this way:

class Thief: sneaky = True

and the same attribute (sneakiness) set within the init, like this:

def __init__(self, name sneaky= True, **kwargs):

?? And while I'm asking questions-- in the next video Kenneth types "pass" beneath the subclass's init: what does "pass" mean? Is the subclass's init a separate thing from the superclass's init? Is the new init (the subclass's init) the thing that overrides the original init (the superclass's init)? Meaning you would ONLY need super() with an over-riding init? Finally (for now): why does Kenneth say the ability to set sneakiness has been lost, when the class still states sneaky = True?

Thanks!

1 Answer

Steven Parker
Steven Parker
231,198 Points

A value set within the class is shared by all instances, but one set in the init method is specific to each instance.

And "pass" basically means "do nothing" and is used as a place holder while creating the structure of a class.