What is the Difference between Interactive and Script Mode in Python Programming?
Last Updated :
29 Dec, 2022
Python is a programming language that lets you work quickly and integrate systems more efficiently. It is a widely-used general-purpose, high-level programming language. It was designed with an emphasis on code readability, and its syntax allows programmers to express their concepts in fewer lines of code. In the Python programming language, there are two ways in which we can run our code:
1. Interactive mode
2. Script mode
In this article, we'll get to know what these modes are and how they differ from each other.
Interactive mode
Interactive etymologically means "working simultaneously and creating impact of our work on the other's work". Interactive mode is based on this ideology only. In the interactive mode as we enter a command and press enter, the very next step we get the output. The output of the code in the interactive mode is influenced by the last command we give. Interactive mode is very convenient for writing very short lines of code. In python it is also known as REPL which stands for Read Evaluate Print Loop. Here, the read function reads the input from the user and stores it in memory. Eval function evaluates the input to get the desired output. Print function outputs the evaluated result. The loop function executes the loop during the execution of the entire program and terminates when our program ends. This mode is very suitable for beginners in programming as it helps them evaluate their code line by line and understand the execution of code well.
How to run python code in Interactive mode?
In order to run our program in the interactive mode, we can use command prompt in windows, terminal in Linux, and macOS. Let us see understand the execution of python code in the command prompt with the help of an example:
Example 1:
To run python in command prompt type "python". Then simply type the Python statement on >>> prompt. As we type and press enter we can see the output in the very next line.
Python3
# Python program to display "Hello GFG"
print("Hello GFG")
Output:

Example 2
Let us take another example in which we need to perform addition on two numbers and we want to get its output. We will declare two variables a and b and store the result in a third variable c. We further print c. All this is done in the command prompt.
Python3
# Python program to add two numbers
a = 2
b = 3
# Adding a and b and storing result in c
c = a + b
# Printing value of c
print(c)
Output:

We can see the desired output on the screen. This kind of program is a very short program and can be easily executed in interactive mode.
Example 3:
In this example, we will multiply two numbers and take the numbers as an input for two users. You will see that when you execute the input command, you need to give input in the very next line, i.e. code is interpreted line by line.
Python3
# Python program to take input from user
# Taking input from user
a = int(input())
# Taking input from user
b = int(input())
# Multiplying and storing result
c = a * b
# Printing the result
print(c)
Output:

Disadvantages of interactive mode
- The interactive mode is not suitable for large programs.
- The interactive mode doesn't save the statements. Once we make a program it is for that time itself, we cannot use it in the future. In order to use it in the future, we need to retype all the statements.
- Editing the code written in interactive mode is a tedious task. We need to revisit all our previous commands and if still, we could not edit we need to type everything again.
Script Mode
Script etymologically means a system of writing. In the script mode, a python program can be written in a file. This file can then be saved and executed using the command prompt. We can view the code at any time by opening the file and editing becomes quite easy as we can open and view the entire code as many times as we want. Script mode is very suitable for writing long pieces of code. It is much preferred over interactive mode by experts in the program. The file made in the script mode is by default saved in the Python installation folder and the extension to save a python file is ".py".
How to run python code in script mode?
In order to run a code in script mode follow the following steps.
Step 1: Make a file using a text editor. You can use any text editor of your choice(Here I use notepad).
Step 2: After writing the code save the file using ".py" extension.
Step 3: Now open the command prompt and command directory to the one where your file is stored.
Step 4: Type python "filename.py" and press enter.
Step 5: You will see the output on your command prompt.
Let us understand these steps with the help of the examples:
Example 1:
In order to execute "Hello gfg" using script mode we first make a file and save it.

Now we use the command prompt to execute this file.
Output:

Example 2:
Our second example is the same addition of two numbers as we saw in the interactive mode. But in this case, we first make a file and write the entire code in that file. We then save it and execute it using the command prompt.

Output:

Example 3:
In this example, we write the code for multiplying two numbers. And the numbers which are to be multiplied are taken by the user as an input. In the interactive mode, we saw that as we write the command so does it asks for the input in the very next line. But in script mode we first code the entire program save and then run it in command prompt. The python interpreter executes the code line by line and gives us the result accordingly.

In this example, we see that the whole program is compiled and the code is executed line by line. The output on the shell is entirely different from the interactive mode.
Difference between Interactive mode and Script mode
Interactive Mode
| Script Mode
|
It is a way of executing a Python program in which statements are written in command prompt and result is obtained on the same. | In the script mode, the Python program is written in a file. Python interpreter reads the file and then executes it and provides the desired result. The program is compiled in the command prompt, |
The interactive mode is more suitable for writing very short programs. | Script mode is more suitable for writing long programs. |
Editing of code can be done but it is a tedious task. | Editing of code can be easily done in script mode. |
We get output for every single line of code in interactive mode i.e. result is obtained after execution of each line of code. | In script mode entire program is first compiled and then executed. |
Code cannot be saved and used in the future. | Code can be saved and can be used in the future. |
It is more preferred by beginners. | It is more preferred by experts than the beginners to use script mode. |
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Types of Network Topology Network topology refers to the arrangement of different elements like nodes, links, or devices in a computer network. Common types of network topology include bus, star, ring, mesh, and tree topologies, each with its advantages and disadvantages. In this article, we will discuss different types of n
12 min read
Java Exception Handling Exception handling in Java allows developers to manage runtime errors effectively by using mechanisms like try-catch block, finally block, throwing Exceptions, Custom Exception handling, etc. An Exception is an unwanted or unexpected event that occurs during the execution of a program, i.e., at runt
10 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Types of Operating Systems Operating Systems can be categorized according to different criteria like whether an operating system is for mobile devices (examples Android and iOS) or desktop (examples Windows and Linux). Here, we are going to classify based on functionalities an operating system provides.8 Main Operating System
11 min read
Steady State Response In this article, we are going to discuss the steady-state response. We will see what is steady state response in Time domain analysis. We will then discuss some of the standard test signals used in finding the response of a response. We also discuss the first-order response for different signals. We
9 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
Java Interface An Interface in Java programming language is defined as an abstract type used to specify the behaviour of a class. An interface in Java is a blueprint of a behaviour. A Java interface contains static constants and abstract methods. Key Properties of Interface:The interface in Java is a mechanism to
12 min read
Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read