Notes

Running Python Programs (Interactive Mode & Script Mode) [ English ]

< Prev Next >

1. Introduction

Python programs can be executed in two main ways:

  1. Interactive Mode
  2. Script Mode

Both methods are useful in different situations. Interactive mode is mainly used for testing and learning, while script mode is used for writing complete programs.

2. Interactive Mode

2.1 What is Interactive Mode?

Interactive mode allows the user to write and execute Python commands one by one. The result of each command is displayed immediately.

It is also known as the Python Shell.

2.2 How to Start Interactive Mode

Open Command Prompt and type:

python

You will see something like:

>>>

2.3 Example

>>> print("Hello Python")
Hello Python

>>> 5 + 3
8

2.4 Features of Interactive Mode

2.5 Limitations

3. Script Mode

3.1 What is Script Mode?

Script mode allows you to write Python code in a file and execute it as a complete program.

The file is saved with a .py extension.

3.2 Steps to Run a Script

Step 1: Create a Python File

Open any editor (Notepad, VS Code, etc.) and write:

print("Hello Python")

Save the file as:

program.py

Step 2: Run the Program

Open Command Prompt and type:

python program.py

3.3 Output

Hello Python

3.4 Features of Script Mode


4. Difference Between Interactive Mode and Script Mode

Feature Interactive Mode Script Mode
Execution Line by line Entire program
Output Immediate After execution
Code Saving Not saved Saved in file
Use Case Testing, learning Full programs
Complexity Simple Complex

5. When to Use Each Mode

6. Summary

< Prev Next >