Page 93 - Information_Practice_Fliipbook_Class11
P. 93

4.4.1 Arithmetic Operators

            The arithmetic operators are used to perform arithmetic operations – addition, subtraction, multiplication, division,
            and exponentiation. Table 4.1 describes some of the arithmetic operators supported by Python.
                                                   Table 4.1: Arithmetic Operators

             Operator   Operation               Explanation                           Examples

             +          addition of numbers     Adds two numeric values.              >>> -45+30
                                                                                          -15

                        concatenation of strings,  Concatenates the string on  the RHS of   >>> "Uttar " + "Pradesh"
                        lists, tuples           the operator to the string on the LHS of       'Uttar Pradesh'
                                                the operator.

             -          subtraction             Subtract the operand on the RHS of the  >>> 100-82
                                                operator from the operand on the LHS.      18
                                                                                      >>> -222-150
                                                                                          -372
             *          multiplication of       Multiplies the operands on either side of  >>> 45*10
                        numbers                 the operator.                              450
                                                                                      >>> -50*3
                                                                                          -150
                        concatenate a string to   Replicates the string.              >>> "Hello"*3
                        itself multiple times                                             'HelloHelloHello'

             /          division                Divides  the operand  on  the LHS  of  the  >>> 410/5
                                                operator by the operand on the RHS and       82.0
                                                yields the quotient as a float value.  >>> -75/6
                                                                                          -12.5
             //         floor division or integer   Divides  the operand  on  the LHS  side  >>> 39//4
                        division                of the operator by the operand on the       9
                                                RHS  and  yields  the  quotient.  When   >>> -75//6
                                                the  operands  include  a  floating  point       -13
                                                number,  the  result  is  a  floating  point   >>> 8//2.5
                                                number  whose value  is  the greatest       3.0
                                                integer  <=  the  number  resulting  from   >>> -8//2.5
                                                division.                                 -4.0
             %          modulus                 Divides  the  operand  (,  say  m)  on  the  >>> 75%4
                                                LHS of the operator by the operand on      3
                                                the RHS of the operator, and yields the  >>> 12.5%4
                                                remainder ( r), according to the equation:     0.5
                                                r = n-(m//n)*n                        >>> -75%4
                                                                                          1
                                                           b
             **         exponentiation          Computes a                            >>> 5**3
                                                                                          125
                                                                                      >>> -4**4
                                                                                          -256
                                                                                      >>> 4**4
                                                                                          256





                                                                                        Data Types and Operators  79
   88   89   90   91   92   93   94   95   96   97   98