Page 290 - AI Ver 1.0 Class 9
P. 290

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

                                                                                 6.0 / 2            3.0
           Division               /      Divides two values.
                                                                                 6 / 2.0            3.0

                                                                                 11 / 2             5.5
                                                                                 5 % 2               1
           Remainder             %       Returns the remainder of a division.
                                                                                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. Following relational operators are provided by Python:

                Name          Symbol                 Purpose                   Example            Output
                                                                                 a = 5
                                         Returns True if both the values are
           Equal to              ==                                              b = 10
                                         same otherwise False.
                                                                                a == b             False


                  288   Touchpad Artificial Intelligence-IX
   285   286   287   288   289   290   291   292   293   294   295