Python_Institute
PCPP-32-101 · Question #52
What is true about a parameter named cls?
The correct answer is C. It is usually used as the first parameter of a class method. By convention, cls is used as the first parameter in class methods to refer to the class itself, similar to how self refers to the instance in instance methods.
Advanced OOP
Question
What is true about a parameter named cls?
Options
- AIt is the name of a module that delivers an abstract method decorator.
- BIt is usually used as the first parameter of a static method.
- CIt is usually used as the first parameter of a class method.
- DIt is usually used as a reference to a class instance.
How the community answered
(33 responses)- B6% (2)
- C91% (30)
- D3% (1)
Explanation
By convention, cls is used as the first parameter in class methods to refer to the class itself, similar to how self refers to the instance in instance methods.
Topics
#cls parameter#class methods#static methods#@classmethod
Community Discussion
No community discussion yet for this question.