Page 230 - Ai_V1.0_Class9
P. 230

Arithmetic Operators

              Arithmetic operators are used to perform mathematical operations on variables and values.
              Following arithmetic operators are provided by Python:

                      Name          Symbol                 Purpose                   Example            Output


                                                                                       2 + 4               6
                 Addition              +       Adds two values.                       2.0 + 4             6.0
                                                                                     "hi" + "all"        "hiall"


                                               Subtracts  second  value  form  the     6 – 2               4
                 Subtraction           –
                                               first value.                            6.0 – 2            4.0

                                                                                        2 * 3              6

                 Multiplication         *      Multiplies two values.                  1.5 * 2            3.0
                                                                                      "Hi" * 3          'HiHiHi'


                                                                                        4 / 2             2.0
                                               Divides  the  first  number  with  the   6.0 / 2           3.0
                 Division               /
                                               second number.                          6 / 2.0            3.0

                                                                                       11 / 2             5.5


                 Remainder or          %       Returns the remainder of a division.    5 % 2               1
                 Modulus                                                              16 % 11              5


                                               Second  number  raised  to  the         5 ** 2              25
                 Exponential           **
                                               power of the first number.             1.5 ** 2            2.25


                                                                                       11 // 2             5
                                               Divides  the  first  number  with  the
                                               second number and returns the          -11 // 2             –6
                 Floor division        //
                                               whole number adjusted left to the       13 // 4             3
                                               number line.
                                                                                      -13 // 4             –4




                            Brainy Fact


                   •  If we use + (Addition) operator with strings, it concatenates two values.
                   •   If we use * (Multiplication) operator with String and integer value, it repeats string value same
                      number of times.



              Relational Operators
              Relational operators or comparison operators compare the values given on both the side of the operators and
              returns the boolean value either True or False.

                    228     Artificial Intelligence Play (Ver 1.0)-IX
   225   226   227   228   229   230   231   232   233   234   235