Page 133 - C_GPT _V4 _class_6
P. 133

OPERATORS
                 In Python, operators can be defined as special symbols that perform arithmetic and logical computations.
                 The values that 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. There are various types of operators
                 in Python. Let us discuss them one by one. Python has the following categories of operators:
                 Arithmetic Operators

                 Arithmetic operators perform arithmetic operations between two operands. The arithmetic operators
                 are defined in the following table:

                  Operator         Name                        Description                       Example        Output
                                                                                              (int x=7 and 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 Integer  Divides and cuts the fractional part from          x // y          2
                              division         the result

                  Program 2: To perform all the arithmetic operators

                     Program2.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)





                     Output

                  Sum is :  13  Difference is :  5  Product is :  36  Decimal division is :  2.25
                  Integer division is :  2  Remainder is :  1  Raised to the power is : 6561




                                                                                                         Python    131
   128   129   130   131   132   133   134   135   136   137   138