Skip to content

Instantly share code, notes, and snippets.

@cemdrk
Created November 16, 2019 13:05
Show Gist options
  • Save cemdrk/1a8dedfa943a4e002c9b83fa02b4f784 to your computer and use it in GitHub Desktop.
Save cemdrk/1a8dedfa943a4e002c9b83fa02b4f784 to your computer and use it in GitHub Desktop.
singledispatch example
from functools import singledispatch
@singledispatch
def power(x, y=2):
return x ** y
@power.register(str)
def _(x, y=2):
return int(x) ** y
print(power(2))
print(power("2"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment