0 votes
1 view
in Python by (12.5k points)

I don't know, why I'm not getting the output for this below program?

from sys import argv

script, first, second, third = argv

print ("The script is called:", script)

print ("Your first variable is:", first)

print ("Your second variable is:", second)

print ("Your third variable is:", third)

Can anyone tell me, How to utilize cmd to pass the arguments?

1 Answer

0 votes
by (26k points)

You were calling it like,

python program.py a1 b2 c3

where it outputs

The script is called: /home/sophia/program.py

Your first variable is: a1

Your second variable is: b2

Your third variable is: c3

sys.argv contains a rundown of strings, each comparing to a command line boundary. The first is consistently the filename of the content; others are the discretionary parameters, requested precisely as they were composed in a shell.

Want to learn python to get expertise in the concepts of python? Join python certification course and get certified

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...