Page 133 - TP_Prime_v2.2_Class_6
P. 133

Features of print( ) Function
                 The print( ) is the first function we learnt in the starting of the chapter. It is used to
                 print the requested values or messages on the screen. The print( ) function converts all

                 messages or values into string before printing or displaying on the screen. The print( )
                 function can be used with multiple parameters. It also introduces a single space between
                 multiple items passed to it. The print( ) function can support multiple escape sequences to
                 format any output on the screen.


                   The input( ) Function                                                                                     INTRODUCTION TO PYTHON

                 We have already studied that Equal to (=) is used to assign a value to a variable. This
                 operator is used to store the value of the variable defined. This value can be changed

                 during execution of the program. It is also possible to get the new value from the user.
                 This is possible using the input() function. The function allows user to change the value of
                 any variable at the time of execution.
                                                                                                                          131






                                                         Using input( ) Function

                 The default data type of input is string, even if you entered a number as input. You cannot
                 perform calculations on a string. To perform calculations, you need to convert the string
                 into an integer or floating-point value. Let us see an example:












                                                      Printing Numbers as String

                 The above output is incorrect. The numbers are just joined together and printed. This is
                 because Python understands the numbers as strings and does not add them as integers.
                   The ‘+’ operator can also be used to concatenate the strings in Python. But, the use of other

                 mathematical operators shows an error if used with strings.













                                               Using Mathematical Operators with String
   128   129   130   131   132   133   134   135   136   137   138