cls
क्यों कभी कभी self
के बजाय पायथन कक्षाओं में एक तर्क के रूप में उपयोग किया जाता है?पायथन कक्षाओं में 'cls' चर का उपयोग क्या किया जाता है?
उदाहरण के लिए:
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)