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
Computer Fundamentals Tutorial This Computer Fundamentals Tutorial covers everything from basic to advanced concepts, including computer hardware, software, operating systems, peripherals, etc. Why Learn Computer FundamentalsYour computer can solve complex problem in milliseconds!Helps you understand how computers work and solve
4 min read
Fundamental
Computer HardwareComputer hardware refers to the physical components of a computer that you can see and touch. These components work together to process input and deliver output based on user instructions. In this article, weâll explore the different types of computer hardware, their functions, and how they interact
10 min read
What is a Computer Software?Computer Software serves as the backbone of all digital devices and systems. It is an integral part of modern technology. Unlike hardware which comprises physical components, software is intangible and exists as a code written in programming language. This article focuses on discussing computer soft
8 min read
Central Processing Unit (CPU)The Central Processing Unit (CPU) is like the brain of a computer. Itâs the part that does most of the thinking, calculating, and decision-making to make your computer work. Whether youâre playing a game, typing a school assignment, or watching a video, the CPU is busy handling all the instructions
6 min read
Input DevicesInput devices are important parts of a computer that help us communicate with the system. These devices let us send data or commands to the computer, allowing it to process information and perform tasks. Simply put, an input device is any tool we use to give the computer instructions, whether it's t
11 min read
Output DevicesOutput devices are hardware that display or produce the results of a computer's processing. They convert digital data into formats we can see, hear, or touch. The output device may produce audio, video, printed paper or any other form of output. Output devices convert the computer data to human unde
9 min read
Memory
Computer MemoryMemory is the electronic storage space where a computer keeps the instructions and data it needs to access quickly. It's the place where information is stored for immediate use. Memory is an important component of a computer, as without it, the system wouldnât operate correctly. The computerâs opera
9 min read
What is a Storage Device? Definition, Types, ExamplesThe storage unit is a part of the computer system which is employed to store the information and instructions to be processed. A storage device is an integral part of the computer hardware which stores information/data to process the result of any computational work. Without a storage device, a comp
11 min read
Primary MemoryPrimary storage or memory is also known as the main memory, which is the part of the computer that stores current data, programs, and instructions. Primary storage is stored in the motherboard which results in the data from and to primary storage can be read and written at a very good pace.Need of P
4 min read
Secondary MemorySecondary memory, also known as secondary storage, refers to the storage devices and systems used to store data persistently, even when the computer is powered off. Unlike primary memory (RAM), which is fast and temporary, secondary memory is slower but offers much larger storage capacities. Some Ex
7 min read
Hard Disk Drive (HDD) Secondary MemoryPrimary memory, like RAM, is limited and volatile, losing data when power is off. Secondary memory solves this by providing large, permanent storage for data and programs.A hard disk drive (HDD) is a fixed storage device inside a computer that is used for long-term data storage. Unlike RAM, HDDs ret
11 min read
Application Software
MS Word Tutorial - Learn How to Use Microsoft Word (2025 Updated)Microsoft Word remains one of the most powerful word processing program in the world. First released in 1983, this word processing software has grown to serve approximately 750 million people every month. Also, MS Word occupies 4.1% of the market share for productivity software.With features like re
9 min read
MS Excel Tutorial - Learn Excel Online FreeExcel, one of the powerful spreadsheet programs for managing large datasets, performing calculations, and creating visualizations for data analysis. Developed and introduced by Microsoft in 1985, Excel is mostly used in analysis, data entry, accounting, and many more data-driven tasks.Now, if you ar
11 min read
What is a Web Browser and How does it Work?The web browser is an application software used to explore the World Wide Web (WWW). It acts as a platform that allows users to access information from the Internet by serving as an interface between the client (user) and the server. The browser sends requests to servers for web documents and servic
4 min read
What is a Excel SpreadsheetExcel works like other spreadsheet programs but offers more features. Each Excel file is called a workbook, which contains one or more worksheets. You can start with a blank workbook or use a template.A worksheet is a grid of 1,048,576 rows and 16,384 columns, over 17 billion cells, for entering and
7 min read
System Software
Programming Languages
C Programming Language TutorialC is a general-purpose mid-level programming language developed by Dennis M. Ritchie at Bell Laboratories in 1972. It was initially used for the development of UNIX operating system, but it later became popular for a wide range of applications. Today, C remains one of the top three most widely used
5 min read
Python Tutorial - Learn Python Programming LanguagePython is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly. It'sA high-level language, used in web development, data science, automation, AI and more.Known fo
10 min read
Java TutorialJava is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. Known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Syntax and s
10 min read
JavaScript TutorialJavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.Client Side: On the client side, JavaScript works
11 min read