Course Content
In-Depth Python OOP
Methods
The methods of the class are functions for instances. You can define a function inside the class and use it from instances:
Output
Note
You can access the instance attributes via the
self
argument inside methods.
The bon.fly(56)
is equal to:
Where self
is the bon
instance and distance
is 56
.
Let's implement the ThreeNumbers
class with a method named total
that returns the sum of three numbers.
Output
So, the self
argument allows access to the values num1
, num2
, and num3
through the instance.
What is a method?
Select the correct answer
Everything was clear?
Section 1. Chapter 7