Python program that takes in command line arguments as input and print the number of arguments.
Get an example to write a Python program that takes in command line arguments as input and print the number of arguments on the output screen.
Example of command line arguments as input and print the number of arguments
1 2 3 4 5 6 7 8 | import sys #Get command line arguments arguments = sys.argv[1:] num_arguments = len(arguments) #Print number of arguments print("Number of arguments:,num_arguments) |
How to Use the Program:
>> Save the program in a file. for example, arguments_count.py.
>> Open a terminal or command prompt.
>> Move to the directory where the program is saved.
>> Run the program with some command line arguments. For example:
1 | python arguments_count.py arg1 arg2 arg3 arg4 |
Output
1 | Number of arguments: 4 |
Check out our other Python programming examples