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 singledispatchmethod | |
class Dog: | |
@singledispatchmethod | |
def bark(self, quality): | |
raise NotImplementedError | |
@bark.register |
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 fancy_print(s): | |
raise NotImplementedError | |
@fancy_print.register(int) | |
def _ints(s): |
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 fancy_print(s): | |
raise NotImplementedError | |
@fancy_print.register(int) | |
def _ints(s): |
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 area(any_object): | |
raise NotImplementedError | |
@area.register | |
def _(any_object: Circle): | |
return math.pi * (math.pow(any_object.radius, 2)) |
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
import math | |
from functools import singledispatch | |
class Square: | |
length: int | |
def __init__(self, length=0): | |
self.length = length |
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 area(any_object): | |
raise NotImplementedError | |
@area.register(Circle) | |
def _(any_object): | |
return math.pi * (math.pow(any_object.radius, 2)) |
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
import math | |
class Square: | |
length: int | |
def __init__(self, length=0): | |
self.length = length | |
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
my_circle = Circle(6) | |
my_square = Square(12) | |
print(area(my_circle)) | |
print(area(my_square)) |
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
def area(any_object): | |
if isinstance(any_object, Circle): | |
return math.pi * (math.pow(any_object.radius, 2)) | |
elif isinstance(any_object, Square): | |
return (math.pow(any_object.length, 2)) |
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
import math | |
class Square: | |
length: int | |
def __init__(self, length=0): | |
self.length = length | |