Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 97 - 2607_Trackpad_Pro_5.1_flipbook_C6
P. 97

    PROGRAMMING MODES IN PYTHON

                     Python provides two basic programming modes: Interactive Mode and Script Mode.

                     INTERACTIVE MODE (IDLE SHELL WINDOW)

                     The  IDLE Shell window
                     is an interactive window
                     where we can type Python
                     code and view the output
                     in the same window. In
                     the IDLE Shell window, the
                     >>> sign appears. Here, we can type our code and get output by pressing the Enter key.

                     SCRIPT MODE (EDITOR WINDOW)

                     Python Shell executes commands immediately and doesn't save them for later use. For multi-
                     line code and to save your work for future use, you should use Python script mode. This allows
                     you to write larger programs and run the same code multiple times. Save your code in a file, for
                     example, filename.py, and run it to see all the output after execution.

                     To open Python’s Editor Window, click on the File        New File option from the Menu bar. The
                     Python's Editor opens. Here, we can type the code..

                     The output is displayed in the Python Shell window.

                              INPUT AND OUTPUT

                     Python  provides  two  commonly  used  functions  input() and  print() for input  and  output
                     respectively.

                     THE input() FUNCTION

                     We use the input() function to take the user’s input while a program is being executed. The
                     general syntax of the input() function is as follows:

                     Variable_name = input(<message to be displayed>)

                                                                                                 Introduction to Python  95

| 92 93 94 95 96 97 98 99 100 101 102 |