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 Python Basics Functions and Looping Expecting Exceptions

Eva Feng
Eva Feng
3,404 Points

when the function doesn't need to take "self"

I have a question about the inputs that functions take. In some of the videos, the functions usually takes an input "self". However in the videos in this course, most of the time "self" is not needed. When is self needed and when is it not?

1 Answer

Steven Parker
Steven Parker
243,874 Points

Functions that are inside a class (known as "methods") take "self" as the first argument because it is given to them automatically by the system. The "self" refers to the instance of the class being used to call the method.

But when you write functions outside of a class, you only include the parameters you need since the system will not be providing any automatically, nor is there any class instance involved by default.