Articles → PYTHON → Command Line Arguments In PythonCommand Line Arguments In PythonIn this article, we will discuss command-line arguments in Python.What Are Command Line Arguments? The command line arguments are the number of arguments specified after the program name when the program is executed using the command line.Consider an example where you are executing the program using the following command in the command prompt.python gyan.py "A", "B"Here, "A" and "B" are command line arguments.Accessing Command Line Arguments In Code You can use sys.argv to access command line arguments. sys.argv is the list of parameters. By default, sys.argv[0] is the name of the program.Example Consider the following code: -import sys if len(sys.argv) > 0: print(sys.argv)Now execute the above code using the command line arguments.Posted By - Karan Gupta Posted On - Sunday, September 12, 2021 Query/Feedback Your Email Id** Subject* Query/Feedback Characters remaining 250**
python gyan.py "A", "B"
import sys if len(sys.argv) > 0: print(sys.argv)
Query/Feedback