Computer Science, asked by eagakovid, 10 months ago

what is the difference between interactive mode and scripting mode in python ??

Answers

Answered by sharmavaishnavi76
10

Answer:

INTERACTIVE MODE

Interactive mode, also known as the REPL provides us with a quick way of running blocks or a single line of Python code. The code executes via the Python shell, which comes with Python installation. Interactive mode is handy when you just want to execute basic Python commands or you are new to Python programming and just want to get your hands dirty with this beautiful language.

To access the Python shell, open the terminal of your operating system and then type "python". Press the enter key and the Python shell will appear. This is the same Python executable you use to execute scripts, which comes installed by default on Mac and Unix-based operating systems.

The >>> indicates that the Python shell is ready to execute and send your commands to the Python interpreter. The result is immediately displayed on the Python shell as soon as the Python interpreter interprets the command.

To run your Python statements, just type them and hit the enter key. You will get the results immediately, unlike in script mode.

Pros and Cons of Interactive Mode

The following are the advantages of running your code in interactive mode:

Helpful when your script is extremely short and you want immediate results.

Faster as you only have to type a command and then press the enter key to get the results.

Good for beginners who need to understand Python basics.

The following are the disadvantages of running your code in the interactive mode:

1. Editing the code in interactive mode is hard as you have to move back to the previous commands or else you have to rewrite the whole command again.

2. It's very tedious to run long pieces of code.

SCRIPT MODE

If you need to write a long piece of Python code or your Python script spans multiple files, interactive mode is not recommended. Script mode is the way to go in such cases. In script mode, You write your code in a text file then save it with a .py extension which stands for "Python". Note that you can use any text editor for this, including Sublime, Atom, notepad++, etc. If you are in the standard Python shell, you can click "File" then choose "New" or simply hit "Ctrl + N" on your keyboard to open a blank script in which you can write your code. You can then press "Ctrl + S" to save it. After writing your code, you can run it by clicking "Run" then "Run Module" or simply press F5.

Pros and Cons of Script Mode

The following are the advantages of running your code in script mode:

1.It is easy to run large pieces of code.

2.Editing your script is easier in script mode.

3.Good for both beginners and experts.

The following are the disadvantages of using the script mode:

1.Can be tedious when you need to run only a single or a few lines of cod.

2.You must create and save a file before executing your code.

Similar questions