Core Concept Mastery • Python Visual Series Module
Methods are functions defined inside a class. They describe the behaviors that objects of that class can perform. Methods can access and modify the object's instance variables through the `self` parameter.
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
print(self.name + " says Woof!")
def rename(self, new_name):
self.name = new_name
my_dog = Dog("Rex")
my_dog.bark()
my_dog.rename("Max")
my_dog.bark()
This Dog class has __init__ (the constructor), bark (prints a greeting), and rename (changes the name). Methods are functions that live inside a class and operate on objects via "self".