QuestionQ134

VerifiedComputer Programming and Python Fundamentals

You run the following command in the terminal:

python index.py Hello  

You want the command to print Hello. What must be inside index.py?

Explanation

Python stores command-line arguments in sys.argv. The script name occupies argv[0], so Hello is at argv[1]; importing argv from sys and printing that element outputs Hello.

Community Discussion

No comments yet. Be the first to start the discussion!