Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 144 - 2620_Birla Open Mind C-6
P. 144

    The print() Function

                  The  print()  function  prints  or sends  the  output  to  the  standard  output  device,  which  is  usually
                  a monitor. This function auto converts the items to strings, i.e., if you try printing a numeric value,
                  the print() function will automatically convert it into equivalent string and print it. The print() function
                  also introduces spaces between items automatically.
                  The general syntax of the print() function is as follows:

                  print [<expression 1> , <expression 2>...]
                  For example:

                  print ("Python is easy").

                  Let's create a program to use the input( ) and print( ) functions.

                                                                                             21 st
                           Double Tap                                                      Century   #Critical Thinking
                                                                                            Skills

                         Guess my name.
                         1. I am a free and open-source programming language.
                         2. I am a command line shell which gives immediate result for each command.

                         3. I save the commands entered by the user in the form of a program.
                         4. I am an option to save the Python program.
                         5. I am an option to run the Python program.

                       VARIABLES IN PYTHON

                  Variables are memory reference points where we store values which can be accessed or changed later.
                  Python has no command for declaring a variable. A variable is created the moment you first assign a
                  value to it. In Python, we do not need to specify the type of variable because Python is a dynamically
                  typed language and it identifies the variable type automatically. Let’s understand this with the help of
                  the given examples.

                    num = 0.4

                    _price = 30.3
                    TOTAL = _price * num

                    print(TOTAL)

                      142  Premium Edition-VI

| 139 140 141 142 143 144 145 146 147 148 149 |