Functools: functools.singledispatch
Let's discover functool modules and how functions can be overloaded.
Overview of singledispatch module
Python recently added partial support for function overloading in Python 3.4. They did this by adding a neat little decorator to the
functools
module called singledispatch
. This decorator will transform our regular function into a single dispatch generic function. Note
however that singledispatch
only happens based on the first argument’s
type.
Simple example of singledispatch()
Let’s take a look at an example to see how this works!
Get hands-on with 1200+ tech skills courses.