PASSING USER INPUT FROM COMMAND PROMPT IN PYTHON


2.png

I have this simple python code saved in my desktop in the folder named as "Python".


1.png

You can see I run the file named "Running_from_cmd.py" from the command prompt. And it shows the correct output. What if I want to pass the input from cmd and the cmd or the IDE shows the output. So for that we have to pass the arguments to the same command line as shown below:


4.png

The code in the IDE should be this:


3.png

argv stands for Argument values and here I have passed the index value of 1 because index value 0 indicates the file name which is Running_from_cmd.py in the command line. 6 is the index value 1 and 4 is the index value 2. The same value passes to the IDE and the output is shown accordingly.

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center