Page 303 - Artificial Intellegence_v2.0_Class_9
P. 303

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
                                                                                     a = 5
                                             Returns True if both the values are
               Not equal to          !=                                             b = 10
                                             different otherwise False.
                                                                                     a != b            True
                                                                                     a = 5
                                             Returns True if first value is greater
               Greater than          >                                              b = 10
                                             than second value otherwise False.
                                                                                     a > b             False

                                                                                     a = 5

                                                                                    b = 10
                                                                                                       True
                                                                                     a < b             True

                                             Returns True if the first value is less   "abc" > "aBc"
               Less than             <                                                                 True
                                             than second value otherwise False.
                                                                                 "67" > "621"
                                                                                (string value are
                                                                                compared using
                                                                                  ASCII code)



                                                                                   Introduction to Python  301
   298   299   300   301   302   303   304   305   306   307   308