Practice mode Python

In a Python method definition, what does the first parameter, conventionally named self, refer to?

Correct answer B. The instance on which the method was called

Explanation

When you call obj.method(), Python passes obj automatically as the first argument, so the method can access that instance's attributes. The name self is only a strong convention, not a keyword. A classmethod receives the class instead, conventionally named cls.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.