Page 85 - TP_Modular_V2.1_Class6
P. 85

Example:

                  Program :                                     Output :

                  # printing a string                           Hello World

                  # print four names                            Reeta
                  print("Hello World")                          Chirag

                  print("Reeta")
                                                                Akshat
                  print("Chirag")
                                                                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
                                                           OR
                                     Multiline                          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.

                 Let us learn about various Python operators.

                 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 right hand operand from left            x – y        4

                                                hand operand.

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




                                                                               Introduction to Programming        83
   80   81   82   83   84   85   86   87   88   89   90