Python Interpreter: Shell/REPL
Python is an interpreter language. It means it executes the code line by line. Python provides a Python Shell, which is used to execute a single Python command and display the result.
It is also known as REPL (Read, Evaluate, Print, Loop), where it reads the command, evaluates the command, prints the result, and loop it back to read the command again.
To run the Python Shell, open the command prompt or power shell on Windows and terminal window on mac, write python
and press enter. A Python Prompt comprising of three greater-than symbols >>>
appears, as shown below.
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 the command prompt to the folder where you have saved this file and execute the python myPythonScript.py
command, as shown below. It will display the result.
Thus, you can execute Python expressions and commands using Python REPL to quickly execute Python code.