Computer Science, asked by Mannjaiswal51, 6 months ago

Name the execution mode convenient for testing a single line code for instant execution. Explain the other execution mode in Python

Answers

Answered by hcps00
1

Explanation:

In Python, there are two options/methods for running code:

Interactive mode

Script mode

In this article, we will see the difference between the modes and will also discuss the pros and cons of running scripts in both of these modes.

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.

C:\Windows\system32>python

Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>>

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. For example, to print the text "Hello World", we can type the following:

>>> print("Hello World")

Hello World

>>>

Here are other examples:

>>> 10

10

>>> print(5 * 20)

100

>>> "hi" * 5

'hihihihihi'

>>>

We can also run multiple statements on the Python shell. A good example of this is when we need to declare many variables and access them later. This is demonstrated below:

>>> name = "Nicholas"

>>> age = 26

>>> course = "Computer Science"

>>> print("My name is " + name + ", aged " + str(age) + ", taking " + course)

Output

My name is Nicholas, aged 26, taking Computer Science

Using the method demonstrated above, you can run multiple Python statements without having to create and save a script. You can also copy your code from another source then paste it on the Python shell.

Consider the following example:

Similar questions