Created
November 16, 2019 13:05
-
-
Save cemdrk/1a8dedfa943a4e002c9b83fa02b4f784 to your computer and use it in GitHub Desktop.
singledispatch example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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