Methods

A method is a function attached to an object.

You have already used methods:

"cat dog".split()

split is a string method.

You can define methods in your own classes:

Call the method with dot notation:

Methods receive self

The first parameter of an instance method is usually named self.

When you call:

record.passed()

Python supplies record as self. That is why you do not pass it manually.

A method that uses object data

Runs locally with Python in your browser.

Ready to run.

Put behavior near the data when it belongs there

This method belongs naturally with ScoreRecord:

It uses the record's own score and answers a question about the record.

But do not put every function into a class. A function such as this can stay plain:

It does not need object state.

Exercise: Call the method

Given record = ScoreRecord("Ada", 8), what expression calls the passed method?

Answer it first, then check.

HintSelect, then call

Use dot notation to select passed from record, then add call parentheses.

SolutionCall record.passed

The complete method call is record.passed(). Python supplies record as the method's self argument.