Python operator module is one of the inbuilt modules in Python. By import operator you can performs various operations and operates two input numbers in a Python program.
Functions supplied by the operator module.
Python import operator
Simple example code.
import operator # input numbers from user x = int(input("Enter first integer number: ")) y = int(input("Enter second integer number: ")) # Adding both input numbers add = operator.add(x, y) print("Addition: ", add) # Subtracting both input numbers sub = operator.sub(x, y) print("Subtraction: ", sub) # Multiply both input numbers mul = operator.mul(x, y) print("Multiplication: ", mul) # Divide both input numbers truediv = operator.truediv(x, y) print("True division: ", truediv) # floor division fldiv = operator.floordiv(x, y) print("Floor division: ", fldiv) # modulus operation mod = operator.mod(x, y) print("Modulus: ", mod) # power value operation pow = operator.pow(x, y) print("Exponentiation: ", pow)
Do comment if you have any doubts or suggestions on this Python operator topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.