Python - Shell (Interpreter)
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.
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.
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.
print ("This is Python Script.") print ("Welcome to Python Tutorial by TutorialsTeacher.com")
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.
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.
Learn about free Python IDE in the next chapter.