×

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

Why learn Python?

All things considered, learning python would be extraordinary, it'll acquaint you with the universe of dynamic programming dialects, if you're somebody who has had a semester of involvement with C. Python...

4 minutes read.

How to Install Pandas in Python?

Pandas is a library created in Python for handling and analyzing data. Pandas provides a variety of procedures and data structures for manipulating time series and numerical data.  Pandas is...

3 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.

Python String zfill() method

Python String zfill() method The string.zfill() method in Python returns a copy of the string while adding the zeros (0) at the beginning of the string, until it reaches the specified...

1 minute read.

Python Queue

Python Queue There are various day to day activities where we find ourselves engaged with queues. Whether it is waiting in toll tax lane or standing on the billing counter for...

7 minutes read.

Closest Pair of Points in Python

We are given an array of n points in the plane, and our task is to find the pair of points in the array that are the closest to each...

3 minutes read.

Iterate through the list in Python

One of the six basic data types of the Python computer language is the list. You must be familiar with the methods and functions that deal with lists in order...

7 minutes read.

How to import numy in python

How to Install NumPy in Python Python is a vast ocean of libraries, modules, and different functions. It has a solution for almost everything. Using Python, we can simplify even a...

3 minutes read.

How to create a file in Python?

How to create a file in python? Files provide us a convenient way of storing our information. Once we have our data, the next task is to store it so that...

3 minutes read.

How to Create an Array in Python?

How to Create an Array in Python In the previous article, we have discussed how to declare an array in Python. So, let's have a quick revision of that, and then we...

5 minutes read.

Python oct() function

Python oct() function The oct() function in Python converts an integer number to an octal string prefixed with “0o”. Syntax oct(x) Parameter x: This parameter represents an Integer Number Return This function returns an octal string. Example 1 #...

1 minute read.

Python Dictionary update() method

Python Dictionary update() method The dictionary.update() method in Python inserts the specified items to the dictionary. Syntax dictionary.update(iterable) Parameter iterable- This parameter represents a dictionary or an iterable object with key value pairs, that will...

1 minute read.

How to slice a list in python

When working with lists, we face situations where we may need a part of the list from one index to the other. Slicing is one of the simpler ways to...

5 minutes read.

Rank Based Percentile GUI Calculator using Tkinter in Python

GUI: The user is provided with information using manipulable visual widgets that don't require command-line input. These interface components respond to the user's interactions per the pre-programmed script, assisting each user's...

3 minutes read.

Notepad++ For Python

In this article, you are going to learn what notepad++ is and how it is integrated with python to use the python programming language. You can also learn how to...

4 minutes read.

Iterate a Dictionary in Python – Part 2

In this tutorial, we will learn above various methods used to Iterate a Dictionary in Python. Dictionary: In Python, a dictionary is an unordered collection of data values that is used to...

3 minutes read.

Python Syntax

Python is a strong object-oriented programming language that is simple to learn. Python was created to be a very readable programming language. The syntax of the Python programming language is...

8 minutes read.

List Comprehension in Python

Sometimes we need new lists that are completely based on previously existing lists, so to perform this operation successfully, some of the programming languages come with a syntactic construct known...

5 minutes read.

Python Set update() method

Python Set update() method The set.update() method in Python updates the current set, by adding items from another set. If an element is common in both the sets, only one appearance of this item...

1 minute read.

Removing the First Character from the String in Python

String The string is the collection of characters. The strings in python are “immutable”; we cannot change a string once they are created. In python, whatever data we take as input...

4 minutes read.