×

How to run Python program in CMD

How to run python program in cmd

Command Prompt provides us all together with a different approach for dealing with our programs. The programs can be executed by accessing the directories.

In this article, we will discuss how we can run python programs in command prompt and what are the various commands we can use that can become a driving force towards our professional growth.

We have already discussed the steps of running a program in Python in previous articles.

Let’s have a quick recall

Running a program in command prompt-

Command Prompt acts as an interpreter in Windows and on specifying the correct path and by using the necessary commands, we can perform the required tasks. Typing 'cmd' in the search area of the taskbar will show the command prompt option and then we can start working on it.

  • Open Command Prompt from the taskbar and run your file by specifying the file name.
  • Make sure you provide the correct destination of your file.

We will execute the following program-

 a=int(input("Enter 1st number: "))         #obtaining first value
 b=int(input("Enter 2nd number: "))       #obtaining second value
 c=a+b                                                   #performing addition
 print("Sum of a and b is {}".format(c))  #displaying the result 

What exactly we need to do here is we will open a text editor in a system like Notepad and then write this program and save this file with an extension .py

Let us how it can be implemented-

  1. Open Notepad in your system and type the following program-
How to run Python program in CMD
  1. Click on File and then click on ‘Save As’. Save your file with the extension .py
How to run Python program in CMD
  1. Open the command prompt and make sure you correctly specify the destination of your file and then type the name of your file to access it.
How to run Python program in CMD
  1. On clicking 'Enter' it will display the output and will ask the user to input the values for the addition of numbers.
  2. Once the values are provided, it will produce the desired output.

Commands that make you savvy with command prompt-

In this section, we will discuss the various commands that will help us to develop deeper insights into how to use the command prompt.

So, let's have a glance at the list of commands and their usage-

The commands in Windows Command Prompt are divided into four categories-

  1. Basics
  2. Files
  3. System
  4. Network

Commands that come under the ‘Basic’ category are-

  1. cls- This command clears the screen.
    1. cmd- This command starts the command prompt on our system.
    1. cd- This command changes the directory.
    1. exit- This command exits the command prompt or file.
    1. time- This command displays and helps us to edit the time of the system.
    1. ver- This command helps us to check the version of our operating system.
    1. echo- This command texts the output on the screen.
    1. date- This command shows and sets the date.
    1. dir- This command lists the contents of a directory.
    1. sort- This command sorts the output on the screen.

Commands that come under the ‘Files’ category are-

  1. type- This command displays the content of text files.
    1. mkdir- This command creates a new directory in the system.
      1. attrib- This command displays the attributes of files.
      1. copy- This command copies the file.
      1. move- This command moves the text files.
      1. replace- This command replaces the file present in our system.
      1. compact- This command displays and changes the file compression.
      1. rmdir- This command deletes the directory in our system.
      1. del- This command deletes one or more files.
      1. rename- This command renames the file in our system.

Commands that come under the ‘System’ category are-

  1. driverquery-It creates a list with all the installed drivers.
  2. format- This command formats a drive specified by the user.
  3. label- This command deletes the label of a drive.
  4. systeminfo- This command provides us with information related to the installation of Windows.
  5. unlock- This command helps in unlocking the locked drivers.
  6. backup- This command creates the backup of files present in the system.

Commands that come under the ‘Network’ category are-

1.telnet- This command helps us to establish communication with the other computer.

2. mount- This command helps in enabling the sharing of the network.

3. ftp- This command facilitates the transfer of data from FTP server to PC and vice versa.

4. hostname- This command gives the name of the current host as an output.


Related Topics

What does base case mean in recursion

Base cases and recursive stages are used to define recursive functions. In a primary subject, we compute the outcome right away, given the function call's arguments. In a recursive step, we...

4 minutes read.

Alexa Python

The cloud-based voice assistant renders text into speech in a female voice. Alexa is a virtual assistant released by Amazon. Using itself as a system for home automation, Alexa can...

4 minutes read.

Best resources to learn Numpy and Pandas in python

In this tutorial, we will discuss the different resources where we can learn about NumPy and Pandas libraries of Python in a more efficient way. NumPy NumPy, a Python library used for...

4 minutes read.

Creating Web Application in python

Web Application :  Web Application is an application software that runs in web browser . Software programs will run on operating system. Whereas Web Applications will run on World Wide Web...

5 minutes read.

Converting Set to List in Python

Converting ‘set’ datatype to ‘list’ datatype is called typecasting. Typecasting in programming is a method to convert one datatype into another datatype. It may happen implicitly by the defined language, called...

3 minutes read.

What is Python 2

Python is a widely used high-level language. The initial work on developing python was begun in the late 1980s. In 1989, Guido Van Rossum started to work on it. Initially,...

3 minutes read.

Python Time Module

Python contains many files that can be imported into a python code and used whenever we want. One of that modules is the time module. It is a good practice...

6 minutes read.

Python Seaborn

Seaborn is an open-source library in Python that is used for data visualization and plotting graphs. The plots are used for the Visualization of data. It is built on top...

10 minutes read.

How to assign values to variables in Python and other languages?

Python makes it simple to construct variables. The value to be stored in the variable should then be written after a suitable name for the variable and the equality sign....

3 minutes read.

How to reverse a string in python

How to reverse a string in python A Brief About Strings- The String is a data type in Python that has a sequence of characters. This series of characters are represented in...

4 minutes read.

Python Argmin

Introduction The argmin function is defined as numpy.argmin(). This function returns the index of the minimum value or element from a Numpy array in a specific axis. An array is taken...

3 minutes read.

Composition in Python

Composition in Python Composition is one of the important concepts of Object-oriented programming (OOPs). Composition basically enables us for creating complex types objects by combining other types of objects in the...

6 minutes read.

How to Install Python In Windows

How To Install Python In Windows? Python is a language that every aspirant developer looks forward to. One thing we must keep in our mind is how to begin our hands-on...

3 minutes read.

How to Install PIP In Python

How to Install PIP In Python The libraries for Python have made our work easier than we expected. From a simple addition of two numbers to applying algorithms on the big...

4 minutes read.

Python logging Module

Python logging Module Introduction By logging word we understand the tracking of the events which happens when we run some software. Logging process is very important part for developing software, debugging...

12 minutes read.

Python Dictionary clear() method

Python Dictionary clear() method The dictionary.clear() method in Python removes all the elements from a dictionary. Syntax dictionary.clear() Parameter NA Return None Example 1 # Python program explaining # the dictionary.clear() method # initialising the dictionary fruits =...

1 minute read.

Python String Negative Indexing

This page contains all the information how to use “Negative indexing“ in Python with the help of using slicing. What is an Index? An index is a numeric value, which is assigned...

3 minutes read.

Python program to count and display vowels in a string

Python program to count and display vowels in a string This python program counts the vowels in a string and displays them on the screen. We can do this in several...

2 minutes read.

Python Set issubset() method

Python Set issubset() method The set.issubset() method in Python returns True if all items in the set exists in the specified set, otherwise it returns False. Syntax set.issubset(set1) Parameter set- This parameter represents the set to check whether...

2 minutes read.

Get index of element in array in python

Index : Index is a number where the element is located in the given list. In other words it is the position of the element in the list. Index can also...

4 minutes read.