Bummer! You have been redirected as the page you requested could not be found.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Basic Object-Oriented Python!
You have completed Basic Object-Oriented Python!
Preview
Learn how to add functions to a class in Python.
- Methods - functions inside of classes. They take self as an argument.
- Calling a method -
instance_name.my_method() - Passing in values -
instance_name.my_method(‘some value’) - Calling a method inside of another - use
self.my_method()instead ofinstance_name.my_method()(sinceselfessentially equalsinstance_name) - Using an attribute -
self.my_attributewhen inside your class
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
In this video, we're going to dive
into how to add methods to a class,
0:00
pass in arguments and call a method.
0:03
Let's start by adding
a method to this car class.
0:06
It will be called stop
0:10
The format is the same as
a regular function, but
0:22
it needs to take self as an argument.
0:25
All methods inside of a class will need to
take self, otherwise it'll throw an error.
0:28
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up