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 trialvincent schouten
9,687 PointsIt's not clear to me the difference between __init__ and setup.
I am full aware of the capabilities of init. It will set given attributes on creaton. But, I am not able to grasp the use of setup. Could somebody please elaborate more on setup? Thank you
2 Answers
Abdul hamid Achik Lopez
15,659 Pointswell, the "init" method is part of the object's methods defined by python, see dir(object) and you will see it, for more info check out the documentation, when you create an instance of a object... the method that automatically runs itself its "init"
however the setup method explained in the video is defined by kenneth, he could had used
def configurate(self):
####instructions
and that would still work the same way.
in other words... "init" runs itself when you make an instance of an object and "setup()" has to be called in order to work
cheers
Anthony Attard
43,915 PointsFrom the teachers notes:
"Wait, why didn't we use __init__
instead of setup?
Well, if we want to have functionality in our Game class for restarting the game, we can call setup() but we wouldn't want to try and re-initialize our class from the inside."
vincent schouten
9,687 Pointsvincent schouten
9,687 PointsHi Abdul, thanks for taking the time to explain it. Highly appreciated! Thanks