-
A method is just a function defined inside a class
-
It shows what a class can do, like behaviour or action
-
You always see
selfas the first argument (it means the method is linked to the object)
Example:
class BankAccount:
def deposit(self, amount): # this is a method
print(f"Deposited {amount}")
-
deposit()is a method -
It belongs to the
BankAccountclass -
It defines what happens when someone deposits money
Types of Methods
-
Instance Method (default one)
-
Class Method
-
Static Method
-
Constructor
Types of Methods (based on logic)
Now, depending on whether the method has logic or just a rule, we call it:
-
Concrete Method
-
Abstract Method