What Is Python Shell?

What Is Python Shell?

Python is one of the most popular interpreted programming languages, meaning it executes code line by line. Python includes an interactive shell that is used to execute a single Python command to get the output. This is also known as REPL (Read, Evaluate, Print, Loop), because it reads the command, evaluates it, prints the result, then loops back to read the command.

When installing Python on a computer, the Python interpreter is normally installed by default in “/usr/local/bin/python3.8,” but in Unix, if the shell’s search path is set to “/usr/local/bin,” it may be simply started by running the python3.8 command. Now, because directory selection is an installation option where the interpreter is present, other locations are possible as well. You can check with your system administrator about this. (for example, /usr/local/python).

How to open Python Shell on Windows?

Simply open Command Prompt on your computer, then type python and hit Enter.

Simply open Command Prompt on your computer, then type python and hit Enter.

After pressing the Enter button, a Python prompt is immediately displayed in front of you with three greater-than symbols (>>>). Thus, now you can enter a single statement to get the result, for example, calculate a simple statement like 5+2, then press enter and the result will be displayed on your screen.

It can function as a basic calculator, performing various arithmetic calculations.

It can function as a basic calculator, performing various arithmetic calculations.

As you can see in the above examples, Python Shell executes a single statement at a time. If you want to come out of the Python Shell or to end it then you have to type the Command exit() or quit() and press enter. And after that, the three greater-than signs (>>>) will be gone, and you’ll know you’ve exited the shell.

And if you want to execute several statements, then you must first create a Python file with an a.py extension and then write a Python script (multiple statements).

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

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

Save it with the a.py extension and the name test.py, as shown above, then navigate the command prompt to the folder where you saved this file. If you stored it in a different folder or drive, right-click on the saved.py file, select Properties, and copy the Location as shown in the picture below, which is highlighted in blue.

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

If your folder or file exists in the C: drive, then type the command “cd (file destination). Otherwise, change the drive by simply typing the drive. In my situation, it’s the D: Drive, so I’ll type D: and press enter, and then proceeding with the cd command. “cd D:python files” and press enter to change the directory, as seen above.

Then, execute the script by writing the “python test.py” command which is shown below.

execute the script by writing the “python test.py” command as shown below.

And that way, you can execute Python statements and commands using Python Shell.

1 thought on “What Is Python Shell?”

  1. Pingback: what is Python Shell?

Comments are closed.

Scroll to Top