Now that we have looked at some example programs, we would like to learn how to begin the actual process of writing a program in Python. There are a variety of ways to tell Python to execute the code we type. Let us take a look at a few ways.
The Interactive Prompt.
Perhaps the simplest way to run Python is to type them at Python's interactive command line,also called as interactive prompt. Assuming the interpreter is installed as an executable program on your system, the way to start an interactive interpreter session is usually just to type python at your operating system’s prompt,without any arguments. The familiar Python Interpreter opens up with the sign:
>>>
ready to accept commands!
Now,the interpreter is ready to execute any coomand you type. For example,typing
>>> print("Hello,World") will produce the output
Hello,World!
When coding interactively like this, you can type as many Python commands as you like; each is run immediately after it’s entered.To exit an interactive session like this one and return to your system shell prompt,on MS-DOS and Windows systems, type Ctrl-Z to exit.
The benefits of Interactive prompt
The interactive prompt runs code and echoes results as you go, but it doesn’t save your code in a file. Although this means you won’t do the bulk of your coding in interactive sessions, the interactive prompt turns out to be a great place to both experiment with the language and test program files on the fly.
Now, let us take a look at IDLE.(Integrated Development Learning Environment)
The IDLE User Interface
So far, we’ve seen how to run Python code with the interactive prompt.If you’re looking for something a bit more visual, IDLE provides a graphical user interface for doing Python development, and it’s a standard and free part of the Python system. It is usually referred to as an integrated development environment (IDE), because it binds together various development tasks into a single view.
In short, IDLE is a GUI that lets you edit, run, browse, and debug Python programs,all from a single interface. For many, IDLE represents an easy-to-use alternative to typing command lines, and a less problem-prone alternative to clicking on icons.
IDLE Basics
Let’s take an example. IDLE is easy to start under Windows—it has an entry in the Start button menu for Python.The Python shell window that opens initially is the main window, which runs an interactive session (notice the >>> prompt). This works like all interactive sessions—code you type here is run immediately after you type it—and serves as a testing tool. To make (or edit) a source code file under IDLE, open a text edit window: in the main window, select the File pull-down menu, and pick New Window (or Open... to open a text edit window displaying an existing file for editing). It is in the text edit window that you write your actual program.
To run a file of code that you are editing in IDLE, select the file’s text edit window, open that window’s Run pull-down menu, and choose the Run Module option listed there (or use the equivalent keyboard shortcut, given in the menu). Python will let you know that you need to save your file first if you’ve changed it since it was opened or last saved and forgot to save your changes. When run this way, the output of your script and any error messages it may generate show up back in the main interactive window (the Python shell window).
IDLE is free, easy to use, portable, and automatically available on most platforms.
Thus,now, I have completed the lesson and the students can now start writing simple programs in Python. They may feel free in contacting me in case thay are experiencing any problems.