Skip to content

Instantly share code, notes, and snippets.

@raeq
Last active May 2, 2021 12:23
Show Gist options
  • Save raeq/b62ddf0c7b32e0923943d6dbeea9e1bb to your computer and use it in GitHub Desktop.
Save raeq/b62ddf0c7b32e0923943d6dbeea9e1bb to your computer and use it in GitHub Desktop.
A simple overload using singledispatch
from functools import singledispatch
@singledispatch
def area(any_object):
raise NotImplementedError
@area.register(Circle)
def _(any_object):
return math.pi * (math.pow(any_object.radius, 2))
@area.register(Square)
def _(any_object):
return (math.pow(any_object.length, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment