Page 95 - KEC Khaitan C8.5 Flipbook
P. 95

ARITHMETIC OPERATORS


                 Arithmetic  operators  in  Python  are  used  for performing  mathematical  calculations  such  as
                 addition, subtraction, multiplication, and division. These operators are essential in programming
                 for tasks like financial calculations, scientific computing, and data analysis. Python provides a
                 set of arithmetic operators that work with integers, floating-point numbers, and even complex
                 numbers.

                 Some arithmetic operators are as follows:


                                                                                   Example
                     Operator           Name               Description           (x=7 and y=3)          Output



                                                      Adds values on either
                          +         Addition                                          x + y                10
                                                      side of the operator

                                                      Subtracts right hand
                         –          Subtraction       operand from left hand          x – y                4
                                                      operand

                                                      Multiplies values on
                         *          Multiplication    either side of the              x * y                21
                                                      operator

                                                      Divides left hand
                          /         Division          operand by right hand           x / y            2.3333335
                                                      operand

                                                      Divides left hand
                                                      operand by right hand
                         %          Modulus                                           x % y                 1
                                                      operand and returns

                                                      the remainder
                                                      Performs exponential
                         **         Exponentiation    (power) calculation on         x ** y               343

                                                      operands

                                                      Divides and returns the
                                    Floor or Integer
                         //                           integer part from the           x // y               2
                                    division
                                                      result.












                                                                                    Tokens and Data Types in Python  93
   90   91   92   93   94   95   96   97   98   99   100