Lessons
Courses

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

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 + 38

2.4 Features of Interactive Mode

  • Executes code line by line
  • Shows immediate output
  • Useful for testing small programs
  • Helpful for learning and debugging

2.5 Limitations

  • Not suitable for large programs
  • Code is not saved automatically
  • Difficult to manage complex logic

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

  • Suitable for large programs
  • Code is saved in files
  • Easy to edit and reuse
  • Supports complex logic and projects

4. Difference Between Interactive Mode and Script Mode

FeatureInteractive ModeScript Mode
ExecutionLine by lineEntire program
OutputImmediateAfter execution
Code SavingNot savedSaved in file
Use CaseTesting, learningFull programs
ComplexitySimpleComplex

5. When to Use Each Mode

  • Use Interactive Mode when:

    • Testing small code snippets
    • Learning Python
    • Debugging
  • Use Script Mode when:

    • Writing full programs
    • Developing applications
    • Reusing code

6. Summary

  • Python programs can be executed in two modes: Interactive and Script Mode.
  • Interactive Mode executes code line by line and is useful for quick testing.
  • Script Mode runs complete programs stored in .py files.
  • Both modes are important for effective Python programming.