Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Methods are class attributes - add method

In this example we are going to add a newly created method to the class. (monkey patching)

class Person():
    def __init__(self, name):
        self.name = name

y = Person('Jane')
print(y.name)           # Jane

def show(some_instance):
    print("Hello " + some_instance.name)

Person.show = show
y.show()                # Hello Jane