What is a “method” in Python?

It’s a function which is a member of a class:

class C:
    def my_method(self):
        print("I am a C")

c = C()
c.my_method()  # Prints("I am a C")

Simple as that!

(There are also some alternative kinds of method, allowing you to control the relationship between the class and the function. But I’m guessing from your question that you’re not asking about that, but rather just the basics.)

Leave a Comment