← Go Back

How to Get Command Line Arguments

The sys.argv object is a list containing arguments passed to the current script.

import sys

If this code is invoked using python test.py hello world, the result would be:

['test.py', 'hello', 'world']

Remember that the first item in the list is always the name of the script or program, thus arguments are found in sys.argv[1:]:

args = sys.argv[1:]

sys console terminal

🐍 You might also find interesting: