Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
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()
(sinceself
essentially equalsinstance_name
) - Using an attribute -
self.my_attribute
when inside your class
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Dominick Chism
8,857 Points4 Answers
-
Setiawan Angga
606 Points1 Answer
-
Karyna Reut
1,611 Points2 Answers
-
Pedro Leitao
1,615 Points1 Answer
-
Faris Rachmadyo
1,760 Points2 Answers
-
Kylie Nonemaker
1,190 Points1 Answer
-
Lewis Mrozek
1,538 Points1 Answer
-
Roberto Quintero
9,046 Points1 Answer
-
aaron roberts
2,004 Points3 Answers
-
aaron roberts
2,004 Points2 Answers
-
Kasey Knudsen
5,888 Points3 Answers
-
PLUS
Luke Tate
Courses Plus Student 2,256 Points2 Answers
-
Timothy Mattingly
15,986 Points1 Answer
-
cgeorge
5,493 Points2 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
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