Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (16.4k 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 (26.4k 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
asked Feb 19, 2021 in Python by laddulakshana (16.4k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...