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 trialaa114
1,697 PointsWhat is __init__ ?
What is init ? please do not copy from python docs. they are over my head at this level. I'm looking for an explanation in laymen terms.
thanks
2 Answers
Steven Parker
231,198 PointsThe simple answer is that "__init__
" is the method that automatically runs when you create a new object. It typically will set up any conditions that the object needs to begin with.
For example, if your object was a counter, the "__init__
" method might set an internal "total" variable to 0.
Stephani Dudrak
1,614 PointsI'm pretty sure init tells python what to expect when it starts. So when you DEFine an INITial object (create a new thing in a class), you can tell python what to expect. def init(self, name, sneaky=True) in the Thief class means python expects each new Thief to have a name, and will make them sneaky unless the user changes it.