mercredi 16 décembre 2015

Iterate through a sequence of operators

Is it possible/Is there a way to iterate through a sequence of operators as in the following example?

a, b = 5, 7
for op in (+, -, *, /):
    print(a, str(op), b, a op b)

One possible use case is the test of the implementation of various operators on some abstract data type where these operators are overloaded.

Aucun commentaire:

Enregistrer un commentaire