What is Python?
Python is an open-source, object-oriented, high-level programming language that is used for web application development. It is one of the simplest scripting languages with simple syntax and great readability. The productivity and performance of Python programs are much superior to the other web application development languages.
In this article, you will learn how to run your first python program from command line in Windows.
Components required to execute a python program.
There are following two major components required to execute a Python program
- Python: Download and install the latest version of Python on your system.
- Program File: Write your Python program and store it in the file with .py extension.
What is the extension of python program file?
Python programs are stored in the files with a .py extension.
How to create a file with .py extension?
You can create a .py file by saving any file with .py extension. Here are the steps to store your python program in a .py file.
Step 1: Open Notepad or any text editor and write your Python program.
Step 2: Go to the File menu of Notepad and click on the Save As option.
Step 3: In the ‘Save as type‘ box, select All Files (*.*) and in the ‘File name‘ box, type the name of the file with .py extension as shown below.
Step 4: Click on Save. The program file with a .py extension gets created at the selected location
Note: You can also write your Python program in a text file and then change the extension of the file from “.txt” to “.py”.
Steps to run your first python program:
Step 1: Create a program file
Write the following simple python program and store it in a file with the .py extension as explained in the previous step. For this example, we have saved the code in First_Program.py file
As an example, write the below sample code in Notepad or any other text editor and save the file with .py extension. We are saving with name First_Program.py .
# Your First Program print("Welcome to TechSupportWhale!")
In this code, the first line represents a commented text starting with #. The commented lines are skipped during code execution like any other language. This is called single-line comment in Python programming. Read how you can comment a block of code in python or multi-line comment in Python Programming.
Step 2: Execute the program
- Search for cmd in the Windows search and open the Command Prompt.
- Type cd and enter the folder path where your program file is stored. It will change the command prompt directory to the target path.
- Type the python command as below to execute the program
The output “Welcome to TechSupportWhale!” is printed in the command prompt.
If you get “‘python’ is not recognized as an internal or external command, operable program or batch file.” error message then check python is not recognized as an internal and external command article to resolve the issue.
I hope this article helped you to execute your first python program in command line. If you face any issues while executing your python program then feel free to mention them in the comment section, we will try to resolve your query as best as we can.
Happy learning !!!