I have a class Foo
which contains one of math comparison operations op
as a string: '<', '>' or '='. Also Foo
contains a number val
.
class Foo:
def __init__(self, operation: str, value: int):
self.op = operation
self.val = value
In my code I read a number from input and compare it to Foo
's class exemplar value using Foo
's contained operation:
f = Foo('<', 15)
to_check = int(input())
if f.op == '<':
if to_check < f.val:
# ...
elif f.op == '>':
if to_check > f.val:
# ...
elif f.op == '=':
if to_check == f.val:
#...
Is there any way to do it simpler or more elegant?