Instance Method

Method (Python)

A method in Python is a function defined inside a class using the def keyword.

This page covers Method in Python. For a language-agnostic introduction, see Method.

Defining a Method#

Every instance method in Python takes self as its first parameter. self is a reference to the object the method is being called on.

class Player:
    def greet(self):
        print("Hello!")

By convention, method names use snake_case: greet, play, get_score.

Return Values#

Use return to send a value back from a method. A method without a return statement returns None.