Page 109 - Plus_V2.2_C6_Flipbook
P. 109

Example:

                       Program :                                    Output :
                       # printing a string                          Hello World
                       #print five names                            Rachna

                       print("Hello World")                         Sambhav
                       print("Rachna")                              Akshat
                       print("Sambhav")                             Tushar
                       print("Akshat")

                       print("Tushar")
                 However, the text written inside triple quotes (''' or ''"") is also considered as comment. You can use
                 the triple quotes to write multiline comments. For example:


                                  '''This is                         """This is
                                     Multiline              OR          Multiline
                                     Comment'''                         Comment"""


                        OPERATORS

                 In Python,  operators can  be  defined  as  special  symbols  which perform arithmetic  and  logical
                 computation. The values which the operators use to get the output are called operands. For example,
                 in the expression 10 – 5, 10 and 5 are operands and the minus (–) sign is the operator.
                 Python divides the operators in the following categories.

                      Arithmetic Operators

                 Arithmetic operators perform arithmetic operations between two operands. The arithmetic operators
                 are defined in the following table:

                  Operator Name                Description                                      Example      Output
                                                                                              (x=7 and y=3)
                      +      Addition          Adds values on either side of the operator.        x + y         10
                      –      Subtraction       Subtracts the right-hand operand from the          x – y         4
                                               left-hand operand.
                      *      Multiplication    Multiplies values on either side of the operator.  x * y         21
                      /      Division          Divides left-hand operand by right-hand            x / y        2.33
                                               operand.
                      %      Modulus           Divides left-hand operand by right-hand            x % y          1
                                               operand and returns the remainder.
                      **     Exponentiation    Performs exponential (power) calculation on        x ** y       343
                                               operands.
                      //     Floor or Integer  Divides left-hand operand by right-hand            x // y        2
                             division          operand and round off the result to the
                                               nearest whole number.



                                                                                        Introduction to Programming  107
   104   105   106   107   108   109   110   111   112   113   114