culTest

    One of the 50 questions in this topic

    How much do you know about Python?

    What is a class method in Python?

    Answers

    A method defined within a class
    A method that receives the class as the first parameter instead of the instanceCorrect
    A method that can only be called by the class, not by instances
    A method that cannot be overridden in subclasses

    A class method is defined with the @classmethod decorator and automatically receives the class (cls) as the first parameter instead of the instance (self). You can access and modify class attributes but not instance attributes. They are useful for alternative factory methods, for modifying shared class state between all instances, and for creating methods that work with inheritance more intuitively than static methods.