Run python program in terminal

Python programming is free and easy to learn. Before we run python in terminal, we need to install a Python interpreter. The latest version of python is python 3.8.1(3.X), Which you need to download from python.org and install it.

Install Python

Most of the python tutorials assume that the user knows how to write and run the program. Once you downloaded the python installation file, follow the below steps. Whether you are a Windows user or a Mac user, you can follow the same steps.

Step 1: Download Python 
Download Python
Download Python

Step 2: Install Python on Windows/Mac
Make sure you check the option "Add Python 3.8 to PATH", Later in this article we will showcase the reason behind it.
Install Python on Windows/Mac
Install Python on Windows/Mac

Step 3: Python installation setup progress
Python installation setup progress
Python installation setup progress

Step 4: Python is successfully installed, click on close.


How to run python program in terminal

Here I will teach you ways to run python program in terminal. Mac users can follow the same steps to run python program in shell. We will see 3 ways to run the python program.

1. How to tun python program in cmd (Windows command prompt)

As mentioned earlier in this article, while installing python we have checked the option "Add Python to PATH". Here when you use the windows command prompt, you first need to invoke the python interpreter. For that, write simple command "python" and hit the enter button.
How to tun python program in cmd (Windows command prompt)

As you can see in the above image, it starts python interpreter and you can see 3 >>> sign. After that, you can write a simple Hello World program using the print() function.

2. How to run python program using python command line

As soon as you start the python command line, it automatically starts a python interpreter. You can directly write a simple Hello World program using the print() function.
How to run python program using python command line

3. How to run python script from python command line

Open notepad and write a program, save it as "Helloworld.py". Now open windows command prompt, go to the path "cd Desktop" where you have saved the file. After that write command "python Helloword.py" and press enter to run.
How to run python script from python command line

Post a Comment

0 Comments