cls in Python

Python Methods and Functions

The name for the argument representing the current class.

cls is the default name for the first argument to class methods

Notes

Nothing prevents you from changing this name and using any other, but neglecting this long-standing convention may mislead the readers of your code.


During the execution of a class method, the first argument will automatically contain a class (there is no special need to rewrite it).

  class MyClass: 

@classmethod
def say (cls):
print (cls)


MyClass.say () # __main __. MyClass





Get Solution for free from DataCamp guru