Classes in Python

Introduction

The difference between a method and a function

A method here means a regular method, not a static one and not a classmethod A method is a function within some class.

A method expects to be applied to an object of its class

By default you have to pass an object of its class to a method.

A function expects certain arguments to be passed to it

The arguments can be both standard objects and objects of a user-defined class. This is determined when the function is declared

You can pass nothing at all to a function and it will still work.

Objects

All classes in Python except Exception inherit from object

>>> o = object()
>>> dir(o)

['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

Article author: Andrei Olegovich