(no title)
bicarbonato | 3 years ago
class BinOp:
def __init__(self, left, right, operator):
self.left = left
self.right = right
self.operator = operator
sum_of_ints = BinOp(left=1, right=1, operator='+')
match sum_of_ints:
case BinOp(left=int(left), right=int(right), operator='+'):
print(f'Summing int {left} + {right}')
case BinOp(left=str(left), right=str(right), operator='+'):
print(f'Concateneting strings {left} + {right}')
case _:
print('Don\'t know how to sum this')
sealeck|3 years ago
Not sure if there are any runtime checks for this?
danuker|3 years ago