Python 3 operator.div?

I have a little problem with randomly generated statements in Python 3.

import operator
hardOperators = [operator.add, operator.sub, operator.mul]
random_hardOperator = random.choice(hardOperators)

So you see that I have operator functions add, suband mul. But when I try to add a statement div, I get a message saying that operator has no attribute 'div'.

I had never tried using random operators in Python before, so this may seem like a dumb question, but this is the one that gives me hell in debugging.

+4
source share
1 answer

In Python 3, no operator.div, no; which existed only in Python 2 .

operator.truediv() function, operator.floordiv() . ( ) , Python 2 / , , float , , .

+6

All Articles