Learn Python – How to run Python Program?- Basic and advance

Python programmers have to understand each and every viable way to run the Python scripts or code. This is the only way to confirm whether code is working as we want. Python interpreter is accountable for executing the Python scripts. Python interpreter is a piece of software program which works between the Python program and computer hardware. Here we are describing the collection of ways to run Python scripts.

The operating system command-line or terminal.

The Python interactive mode.

The IDE or Text editor

The file manager of system.

The operating system command-line or Terminal

We can run the Python code the usage of a command line because in Python shell as soon as we shut the session, we will lose the entire code that we have written. So it is precise to write a Python code the use of the simple text files. The textual content file need to retailer as .py extension. Let’s see the following example.

We write the Python print assertion and keep it as sample.py in working directory. Now, we will run this file using the command-line.

Using the Python command line

Open the command line to run a Python script. We want to type the python, observed by using the file name to execute the file. Now, hit the enter key, and if there is no the error in file, we will see the output as follows.

The Python interactive mode

To run the Python code, we can use the Python interactive session. We need to start Python interactive session, simply open a command-line or terminal in start menu, then type in python, and press enter key.

Here is the example of how to run Python code using interactive shell.

It allows us to test each and every piece of code, and this facility makes it an first-rate improvement tool. But once we shut the session it will lose all code that we have written.

Below are the few selections to exit the interactive mode.

Type built-in functions quit() or exit(). Or

Type the enter ctrl+ Z key combination to end the current session of Python interactive shell.

The IDE or Text Editor

The IDE stands for Integrated Development Environment. There are various IDEs but Pycharm is Python’s most famous and useful text editor among them. It is advocated for creating large and extra complicated applications. Here are the use of the Pycharm to run python script.

Create a new assignment and then create a new Python file the usage of the .py extension.

Now, click on on the green button and it will exhibit the output as follows.

The file manager system

The Python file can run by double-clicking on its icon in a file manager. This manner can also not be extensively used in the improvement stage. The file need to be related with the .py or .pyw with the program python.exe, respectively.