OA. free
Free
MathWorks Quantitative Aptitude Quantitative Aptitude Medium

What is the value stored in sys.argv[0]?

MathWorks aptitude question, verified with a worked answer. Free to practise - no sign-up.

What is the value stored in sys.argv[0]?

Pick ONE option

Choose one option.
Show answer & explanation
Answer: B. the program's name

In Python, sys.argv is a list of command-line arguments passed to a script. sys.argv[0] always contains the name of the script itself (the program name), not an argument. sys.argv[1] and onwards contain the actual command-line arguments provided by the user.

Step-by-step Derivation:
When you run a Python script like python myscript.py arg1 arg2, sys.argv becomes ['myscript.py', 'arg1', 'arg2']. Therefore, sys.argv[0] is 'myscript.py' (the program name). It is always accessible and is not the first argument—it's the zeroth element by convention.