Methods
You have already come across one special method, the init
method. However, the power of classes will start to become more obvious to you as you begin writing our own custom methods. There are three types of methods you will explore in the following sections:
- Instance methods
- Static methods
- Class methods
Instance Methods
Instance methods are the most common type of method you will need to use. They always take self as the first positional argument. The __init__
method discussed in the previous section is an example of an instance method.
Here is another example of an instance method, extending our Circle
class from Exercise 72, Creating a Circle Class:
import math class Circle(): is_shape = True def __init__(self, radius, color='red'): self.radius = radius self.color...