Practice mode Python

How does a @staticmethod differ from a @classmethod in Python?

Correct answer B. A static method receives no implicit first argument, while a class method receives the class as cls

Explanation

A static method behaves like a plain function placed in the class namespace and gets no automatic first argument. A class method receives the class it was called on as its first argument, which makes it useful for alternative constructors that work correctly in subclasses. Both can be called on the class or an instance.

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.