0% found this document useful (0 votes)
23 views2 pages

Experiment-1 123008

The document introduces the basics of using Python and its interpreter, covering both interactive and script modes. Interactive mode allows for immediate execution of single statements, while script mode enables writing and saving multiple instructions in a file with a '.py' extension. It also provides guidance on executing scripts and includes visual references for better understanding.

Uploaded by

arvisquad1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Experiment-1 123008

The document introduces the basics of using Python and its interpreter, covering both interactive and script modes. Interactive mode allows for immediate execution of single statements, while script mode enables writing and saving multiple instructions in a file with a '.py' extension. It also provides guidance on executing scripts and includes visual references for better understanding.

Uploaded by

arvisquad1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment-1

Objective: Getting started with Python and IDLE in interactive and batch modes.
Explanation: To write and run (execute) a Python program, we need to have a Python interpreter
installed on our computer or we can use any online Python interpreter. The interpreter is also called
Python shell. A sample screen of Python interpreter is shown in Figure 1:

Figure 1: Python interpreter or shell


In the above screen, the symbol >>> is the Python prompt, which indicates that the interpreter is
ready to take instructions. We can type commands or statements on this prompt to execute them
using a Python interpreter.
There are two ways to use the Python interpreter:
1. Interactive mode
2. Script mode
Interactive mode allows execution of individual statement instantaneously. Whereas, Script mode
allows us to write more than one instruction in a file called Python source code file that can be
executed.
Interactive Mode
To work in the interactive mode, we can simply type a Python statement on the >>> prompt
directly. As soon as we press enter, the interpreter executes the statement and displays the
result(s), as shown in Figure 2.
Figure 2: Python interpreter in interactive mode

Working in the interactive mode is convenient for testing a single line code for instant execution.
But in the interactive mode, we cannot save the statements for future use and we have to retype
the statements to run them again.
Script Mode
In the script mode, we can write a Python program in a file, save it and then use the interpreter to
execute it. Python scripts are saved as files where file name has extension “.py”. By default, the
Python scripts are saved in the Python installation folder. To execute a script, we can either:
1. Type the file name along with the path at the prompt. For example, if the name of the file
is prog1.py, we type prog1.py. We can otherwise open the program directly from IDLE as
shown in Figure 3.
2. While working in the script mode, after saving the file, click [Run]->[Run Module] from
the menu as shown in Figure 4.
3. The output appears on shell as shown in Figure 5.

Program1: Write a program to show print statement in script mode.

Figure 3: Python source code file (prog1.py)

Figure 4: Execution of Python in Script mode using IDLE

Figure 5: Output of a program executed in script mode

You might also like