Talk at the July ChennaiPy meetup

On the 28th, I gave a talk at the ChennaiPy meetup group on Dunder methods in Python. You can find the Jupyter Notebook that I used to present the content in Github.

To give you an overview of the talk, I introduced a number of dunder methods in Python, methods which provide functionality to make your custom objects mimic native Python objects.

If you didn't know, dunder is short for double underscore. A common dunder method that we all come across in Python classes is the `__init__` method, which is used to initialize an object during instantiation. Dunder methods are also called magic methods.

The dunder methods of interest are
  • `__repr__` and `__str__` : Provide the official and unofficial string representations of the Objects
  • `__eq__`, `__lt__` and comparisons : Provide the functionality to compare custom Objects in Python.
  • `__hash__` : Are used for operations on members of hashed containers like set, frozenset and dict.
  • `__iter__` and `__next__` : Provide the functionality to create iterators and iterate on the objects in the container/iterator.
  • `__enter__` and `__exit__` : Provide the functionality to enter and exit the runtime context of the Context Manager object.
I introduced a few examples for each of the dunder methods in the talk. Other than for the complaint about there being too much code on the screen, the talk went well overall. There were a number of followup questions on each of the dunder methods, which I was really excited about.

All in all, it had a good time and got good feedback on the talk material.

PS : This talk was meant to refine the content of my proposed talk at PySangramam.

Popular posts from this blog

Arxiv author affiliations using Python

Farewell to Enthought

Elementary (particle physics), my dear Watson