.. role:: python(code) :language: python .. index:: oop; iterator oop; iterable oop; callable oop; class attributes OOP technicalities ------------------ There is much to say about object oriented programming, here the focus is only made on few technical points of python objects useful later in the course. Iterator ^^^^^^^^ An iterator is an object with a :python:`__next__` method. It raises an :python:`StopIteration` exception when there is no 'next' item. Iterable ^^^^^^^^ An iterable is an object with an :python:`__iter__` method which returns an iterator. It is a python object which can be seamlessly iterated over. Callable ^^^^^^^^ An object can be made callable if a :python:`__call__` method is defined. It useful when you need a function with a state. Class attributes ^^^^^^^^^^^^^^^^ Some attributes can be defined directly under the :python:`class` declaration. These attributes are shares between all instances of the class. .. note:: Careful! several very popular libraries use some dark magic to automatically define from class attributes the instance attributes for every instance. :python:`dataclass, attrs, django, pydantic` etc. .. literalinclude:: ../../../../src/tools_methods/basics/oop.py :name: OOP :linenos: :caption: src