Page 112 - Touchpad_Plus_V3.2_Class 6
P. 112
OPERATORS
In Python, operators can be defined as special symbols which perform arithmetic and logical
computation. The values which the operators use to get the output are called operands. For
example, in the expression 10 – 5, 10 and 5 are operands and the minus (–) sign is the operator.
Python divides the operators in the following categories:
Arithmetic Operators
Arithmetic operators perform arithmetic operations between two operands. The different
types of arithmetic operators are +, -, *, /, %, ** and //. These operators are defined in the
following table:
Example
Operator Name Description (x=7 and Output
y=3)
+ Addition Adds values on either side of the operator. x + y 10
– Subtraction Subtracts right hand operand from left x – y 4
hand operand.
* Multiplication Multiplies values on either side of the x * y 21
operator.
/ Division Divides left hand operand by right hand x / y 2.33333
operand.
% Modulus Divides left hand operand by right hand x % y 1
operand and returns remainder.
** Exponentiation Performs exponential (power) calculation x ** y 343
on operands.
// Floor or Divides and cuts the fractional part from x // y 2
Integer the result.
division
Program 1: To perform all the arithmetic operators.
Program1.py
File Edit Format Run Options Window Help
#Program to perform from arithmetic operators
a = 9
b = 4
add = a + b #Addition
sub = a - b #Subtraction
mul = a * b #Multiplication
div = a / b #Division
divl =a // b #Floor Division
mod = a % b #Modulus
power = a **b #Power
print ("Sum is : ", add, " Difference is : " , sub, " Product is : " ,mul, "
Decimal division is : ", div, " Integer division is : " ,divl," Remainder is :
", mod, " Raised to the power is : ", power)
110 Plus (Ver. 3.2)-VI

