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.
The functions provided by operator module can use various mathematical, relational, logical and bitwise operations on two input numbers
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.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.