Skip to content

How to execute a Python program

how to execute a python program

After installing python we need to know how to execute a python program . Here we will see how to execute a python program from PowerShell window , VS code terminal and Jupyter notebook –

You can see in my computer’s D drive there is a folder called “Python tutorial” . This folder contains file1.py (Python file) and file2.ipynb (Jupyter file) . you can see the following image for your reference –

Both the file contains below code –

print("Hello World")

How to execute a python program in Terminal

To execute a python program in PowerShell Terminal we need to open PowerShell from the desired folder . For this reason go to the desired folder in windows file explorer as shown in the above image and click shift and right click together . We need to click on “Open PowerShell window here” option in the upcoming pop-up window .

Now PowerShell window will open . In the PowerShell window we need to type below code and press Enter key –

python file1.py

We can see after pressing of Enter key “Hello World” is printed on PowerShell window . For your case you need to type your file name instead of “file1.py” .

So We successfully executed our python program in PowerShell window .

How to execute a python program in VS code

To execute a python program in VS code we need to open PowerShell from the desired folder . Then we need to click on “Terminal” tab . After that a dropdown will appear . We need to click on “New Terminal” In that dropdown to open a new terminal .

To know how to open a desired folder in VS code click here

We can see a new terminal is opened . Then we need to type “python .\file1.py” and press Enter key . After pressing Enter key we can see our code is executed and printed “Hello World” in the output . In your case you need to type your file name instead of “file1.py” .

So We successfully executed our python program in VS code terminal .

How to execute a python program in Jupyter notebook

To execute a python program in Jupyter notebook we need to open the desired file in Jupyter notebook. Then we need to click on the cell which cell we want to execute and click on the “Run” button . After clicking on the “Run” button we can see our code is executed successfully and printed “Hello World” in the output.

To know how to open the desired file in Jupyter notebook click here

So We successfully executed our python program in Jupyter notebook .

Thank you for reading this Article . If You enjoy it Please Share the article . If you want to say something Please Comment . .

Leave a Reply