Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 121 - 2609_Logiccode
P. 121

    Example:

                       Program:                                         Output:
                       #printing a string                               Hello World

                       #printing four 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 multi-line comments. For example:

                                      '''This is                         """This is
                                                              OR
                                         Multi-Line                         Multi-Line
                                                                            Comment"""
                                         Comment'''

                               OPERATORS

                     In Python, operators can be defined as special symbols which perform arithmetic and logical
                     computation.  The values that  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 an 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:

                                                                                                Example
                      Operator Name                 Description                                 (x=7 and     Output
                                                                                                y=3)

                          +       Addition          Adds values on either side of the           x + y        10
                                                    operator.

                          –       Subtraction       Subtracts right hand operand from left      x – y        4
                                                    hand operand.

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

                          /       Division          Divides left hand operand by right hand  x / y           2.33333
                                                    operand.

                                                                                                      More on Python  119

| 116 117 118 119 120 121 122 123 124 125 126 |