Page 92 - PlugGPT_V2.0_C7_Flipbook
P. 92
Let us learn about various Python operators.
Arithmetic Operators
Arithmetic operators perform arithmetic operations between two operands. The arithmetic
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.33
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 division the result.
Program 1: To perform all the arithmetic operations
Program1.py
File Edit Format Run Options Window Help
#example of arithmetic operators
a = 9
b = 4
# addition
add = a + b
#subtraction
sub = a - b
#division
div - a / b
#floor division
div1 = a // b
#modulus
mod = a % b
#power
power = a ** b
#print results
print (add)
print (sub)
print (mul)
print (div)
print (div1)
print (mod)
print (power)
90 Premium Edition-VII

