Python – Shell

Created with Sketch.

Python is an interpreter language. It means it executes the code line by line. Python provides a Python Shell (also known as Python Interactive Shell) which is used to execute a single Python command and get the result.Python Shell waits for the input command from the user. As soon as the user enters the command, it executes it and displays the result.

To open the Python Shell on Windows, open the command prompt, write python and press enter.



Python Shell

As you can see, a Python Prompt comprising of three Greater Than symbols (>>>) appears.
Now, you can enter a single statement and get the result. For example, enter a simple expression like 3 + 2, press enter and it will display the result in the next line, as shown below.


Command Execution on Python Shell
Command Execution on Python Shell

Execute Python Script

As you have seen above, Python Shell executes a single statement.
To execute multiple statements, create a Python file with extension .py, and write Python scripts (multiple statements).

For example, enter the following statement in a text editor such as Notepad.

Example: myPythonScript.py
print ("This is Python Script.")
print ("Welcome to Python Tutorial by http://python-tutorials.in")

Save it as myPythonScript.py, navigate command prompt to the folder where you have saved this file and execute the python myPythonScript.py command, as shown below.



Python Shell

Thus, you can execute Python expressions and commands using Python Shell. We will be using Python Shell to demo Python features through out these tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *