You can easily pass command line arguments to a Python script. In this tutorial, we will help you to read the command line arguments in a Python script.

Advertisement

Below is the sample Python script, which reads the command line arguments and print details. Create a sample script like script.py and copy the below content.

Then execute the above script with command line parameters.

python script.py first 2 third 4.5 

You will see the results below. The first argument is always the script itself.

Output
Total number of arguments: 5 Argument List: ['script.py', 'first', '2', 'third', '4.5'] First argument: script.py Second argument: first Third argument: 2 Fourth argument: third
Share.
Leave A Reply


Exit mobile version