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

Omar Farag
Omar Farag
4,573 Points

What is __init__ ?

The title says it all. I have no idea what init is for in python. Please help

1 Answer

stjarnan
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
stjarnan
Front End Web Development Techdegree Graduate 56,488 Points

Hi Omar,

init is a function that runs when your class is initialized, like when you create an instance of a class.

You could use it to set the values of the new instance of a class. So every time you create an instance of a class, init will be used to generate the values and attributes for that instance.

I hope that helps

Jonas

Omar Farag
Omar Farag
4,573 Points

So init runs as soon as an instance of a class is created, but no other methods do that? Thanks for the reply btw