← Go Back
If this code is invoked using
Remember that the first item in the list is always the name of the script or program, thus arguments are found in
How to Get Command Line Arguments
Thesys.argv
object is a list containing arguments passed to the current script.import sys
print(sys.argv)
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:]
print(args)
🐍 You might also find interesting: