Introduction to Python – Interactive Mode

In this Page, We are Providing Introduction to Python – Interactive Mode. Students can visit for more Detail and Explanation of Python Handwritten Notes Pdf.

Introduction to Python – Interactive Mode

Interactive mode

One of Python’s most useful features is its interactive interpreter. It allows very fast testing of ideas without the overhead of creating test files, as is typical in most programming languages. However, the interpreter supplied with the standard Python distribution is somewhat limited for extended interactive use. IPython is a good choice for the comprehensive environment for interactive and exploratory computing.

To start interactive mode, launch Python with no arguments (possibly by selecting it from your computer’s main menu). It is a very powerful way to test out new ideas or inspect modules and packages.

Interactive mode prompts for the next command with the “primary prompt”, usually three greater-than signs (>>>); a continuation line is prompted with the “secondary prompt”, which is by default represented by three dots (…). The interpreter prints a welcome message stating its version number and some additional information before printing the first prompt:

$ python
Python 2.7 (#1, Feb 28 2010, 00:02:06)
Type "help", "copyright", "credits" or "license" for more information.
>>>

Continuation lines are needed when entering a multi-line statement. As an example, take a look at this if statement:

>>> the_world_is_flat = 1 
>>> if the_world_is_flat:
... print("Be careful not to fall off!")
...
Be careful not to fall off!

Invoking Python interpreter

In Unix/Linux platforms, the Python interpreter is usually installed at /usr/local/bin/python. It is possible to start interpreter by typing the following command (same command for MS Windows)

$ python

in the shell. Since the choice of the directory where the interpreter lives is an installation option, other places are possible (e.g/usr/local/python is a popular alternative location).

On Windows machines, the Python installation is available at path C:\Python27, though, this can be changed when running the installer. To add this directory to Path environmental variable, type the following command into the MS-DOS command prompt:

set path=%path%;C:\python27

Inputting the end-of-file character (Control-D on Unix, Control-Z on Windows) at the primary prompt causes the interpreter to exit. If that does not work, you can exit the interpreter by typing the following command:

>>> quit()