cls sometimes used instead of
self as an argument in Python classes?
class Person: def __init__(self, firstname, lastname): self.firstname = firstname self.lastname = lastname @classmethod def from_fullname(cls, fullname): cls.firstname, cls.lastname = fullname.split(' ', 1)
The distinction between
"cls" is defined in
PEP 8 . As Adrien said, this is not a mandatory. It's a coding style.
PEP 8 says:
Function and method arguments:
selffor the first argument to instance methods.
clsfor the first argument to class methods.