objects. Objects are instances of classes. Till now, we used various classes without being aware of OOP, every data type which we used, right from integer to dictionary was an object of a class.
selfas the first argument. The self points to the object which calls the method during runtime. When we do a
__init__function is the constructor. It defines how many arguments are passed to the
me = Human()function call. The
initis an optional method, if we don't have an init method, then by default, there are no arguments to the class's initialization call.
__are to be used strictly inside the class, they are syntactically internal methods, albeit they can be used by objects outside of the class declaration, we strongly advice against usage of such internal methods outside of the class declaration.
__add__and you try adding up
you, then it won't work as it wouldn't be able to add both of them. For operations like that, the
__method is invoked on the two objects.
__str__method of that object is called. For this reason, it is essential for declaring an
__str__method for our class, if we want a human friendly format of the print.
Studentclass and perform operations on it by creating a list of
From the official docs: A string literal which appears as the first expression in a class, function or module. While ignored when the suite is executed, it is recognized by the compiler and put into the
__doc__attribute of the enclosing class, function or module. Since it is available via introspection, it is the canonical place for documentation of the object.