Python Operator Functions | Set 1: Read, Discuss, and Practice

Under the module “operator,” Python includes predefined functions for a variety of logical, bitwise, relational, and other operations. In this article, some of the fundamental operations are discussed. 1. add(a, b) : – The addition of the supplied parameters is returned by this method. Operation (a – plus b).

2. The function de”>

# Python code to demonstrate working of

# add(), sub(), mul()

# importing operator module

import

operator

# Initializing variables

a

=

4

b

=

3

# using add() to add two numbers

print

(

"The addition of numbers is :"

,end

=

"");

print

(operator.add(a, b))

# using sub() to subtract two numbers

print

(

"The difference of numbers is :"

,end

=

"");

print

(operator.sub(a, b))

# using mul() to multiply two numbers

print

(

"The product of numbers is :"

,end

=

"");

print

(operator.mul(a, b))