Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

Omar Farag
Omar Farag
4,571 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,571 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