Python tutorial explains it:

import sys

print(sys.argv)

More specifically, if you run python example.py one two three:

>>> import sys
>>> print(sys.argv)
['example.py', 'one', 'two', 'three']
Answer from SilentGhost on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ command-line-arguments-in-python
Command Line Arguments in Python - GeeksforGeeks
sys.argv: A list in Python that contains all the command-line arguments.
Published ย  December 17, 2025
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ argparse.html
argparse โ€” Parser for command-line options, arguments and subcommands
Arguments read from a file must be one per line by default (but see also convert_arg_line_to_args()) and are treated as if they were in the same place as the original file referencing argument on the command line. So in the example above, the expression ['-f', 'foo', '@args.txt'] is considered equivalent to the expression ['-f', 'foo', '-f', 'bar'].
Discussions

Could someone explain command-line arguments in Python?
When you run a python script from the command line, you can pass arguments to the script by adding it after the script name. For example: python my_script.py arg1 arg2 arg3 To utilize these arguments, you can take a look at the sys module (someone else already mentioned it I believe). A quick example would be like this: import sys arg1 = sys.argv[1] arg2 = sys.argv[2] etc... More on reddit.com
๐ŸŒ r/learnpython
6
2
November 13, 2017
Anyone to explain what Command Line Arguments are?
When you run a program in terminal or command prompt you can give it extra information. For example on linux: ls -la "-la" is a command line argument telling "ls" how you want it to act. For example on windows: ipconfig /all "/all" is a command line argument telling "ipconfig" how you want it to act. More on reddit.com
๐ŸŒ r/learnpython
20
19
January 4, 2022
Python beginner: what are command lines arguments and what purpose do they serve in this code
Command line arguments are what you pass to a script when calling it from a windows/linux/whatever command line. For example, if this script was in a file called pw.py, i would call it from a windows command line with this: python pw.py luggage In python, the first command line argument is always the name of the script ('pw.py' in this case). The next argument is 'luggage' More on reddit.com
๐ŸŒ r/learnpython
4
4
January 7, 2016
Command Line Arguments

Can someone explain to me the concept of the command line, and what it means to be running from a command line argument in python?

The 'command line' is referring to a way of interacting with the files and programs on your computer in a text-based (as opposed to graphical) manner. How you access it depends a lot on what kind of system you are using. Here is a crash course if you want to learn more about the command line in general.

(I know I just linked to LPTHW, which is frowned upon in this subreddit, but his command line crash course is genuinely quite good for beginners and is free. Please no one freak out.)

Also, is there a reason that when I try to execute a program, it creates a window that closes almost immediately?

Yes, this is a thing Windows does. It thinks the program is all done, and 'conveniently' closes the window for you. Try adding an input() to the end of your code to keep the window open, or run your code from the command line.

aspects of a code outside of the syntax, such as how the computer knows how to read it, and how it's meant to interact with other programs

That's a pretty broad question, but here's a stackexchange answer that might be relevant.

More on reddit.com
๐ŸŒ r/learnpython
9
14
October 20, 2018
๐ŸŒ
Real Python
realpython.com โ€บ python-command-line-arguments
Python Command-Line Arguments โ€“ Real Python
August 27, 2023 - Unless explicitly expressed at the command line with the option -o, a.out is the default name of the executable generated by the gcc compiler. It stands for assembler output and is reminiscent of the executables that were generated on older UNIX systems. Observe that the name of the executable ./main is the sole argument. Letโ€™s spice up this example by passing a few Python command-line arguments to the same program:
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_command_line_arguments.htm
Python - Command-Line Arguments
C:\Python311>python hello.py Rajan argument list ['hello.py', 'Rajan'] Hello Rajan. How are you? The command-line arguments are always stored in string variables. To use them as numerics, you can them suitably with type conversion functions. In the following example, two numbers are entered as command-line arguments.
๐ŸŒ
Stanford CS
cs.stanford.edu โ€บ people โ€บ nick โ€บ py โ€บ python-main.html
Python main() - Command Line Arguments
$ python3 affirm.py -affirm Lisa Everything is coming up Lisa $ python3 affirm.py -affirm Bart Looking good Bart $ python3 affirm.py -affirm Maggie Today is the day for Maggie $ Command line arguments, or "args", are extra information typed on the line when a program is run.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-command-line-arguments
Python Command Line Arguments: sys.argv, argparse, getopt
5 days ago - For example, if help option is passed then print some user friendly message and exit. Here getopt module will automatically parse the option value and map them. Below image shows a sample run. To learn more, read python getopt module. Python argparse module is the preferred way to parse command line arguments.
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @evaGachirwa โ€บ running-python-script-with-arguments-in-the-command-line-93dfa5f10eff
Running Python script with Arguments in the command line | by Eva Mwangi | Medium
April 22, 2023 - import argparse def get_sum_of_nums(num1,num2,num3): return(int(num1)+int(num2)+int(num3)) if __name__ == "__main__": parser = argparse.ArgumentParser( description="Script that adds 3 numbers from CMD" ) parser.add_argument("--num1", required=True, type=int) parser.add_argument("--num2", required=True, type=int) parser.add_argument("--num3", required=True, type=int) args = parser.parse_args() num1 = args.num1 num2 = args.num2 num3 = args.num3 print(get_sum_of_nums(num1, num2, num3)) Running the script from the command line.
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ command-line-arguments-in-python
Command Line Arguments in Python (sys.argv, argparse) | Codecademy
Learn how to use Python command line arguments with `sys.argv`, `getopt`, and `argparse`. Compare each method and build flexible, user-friendly scripts with real examples.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ command line arguments
Python | Command Line Arguments | Codecademy
September 26, 2025 - This example demonstrates creating a user-friendly command line interface: ... GOOD MORNING, ALICE! ... The argparse module automatically provides help documentation when using -h or --help, validates required arguments, and converts values to appropriate types. It handles argument parsing errors by displaying helpful error messages and usage information. Command line arguments in Python are values passed to a script when executing it from the terminal.
๐ŸŒ
Python
docs.python.org โ€บ 3.3 โ€บ library โ€บ argparse.html
16.4. argparse โ€” Parser for command-line options, arguments and sub-commands โ€” Python 3.3.7 documentation
The ArgumentParser object will ... into Python data types. Filling an ArgumentParser with information about program arguments is done by making calls to the add_argument() method. Generally, these calls tell the ArgumentParser how to take the strings on the command line and turn them into objects. This information is stored and used when parse_args() is called. For example...
๐ŸŒ
Medium
moez-62905.medium.com โ€บ the-ultimate-guide-to-command-line-arguments-in-python-scripts-61c49c90e0b3
The Ultimate Guide to Command Line Arguments in Python Scripts | by Moez Ali | Medium
April 18, 2023 - In Python, command-line arguments are accessed through the sys.argv list. The first item in the list is always the name of the script itself, and subsequent items are the arguments passed to the script. Here is an example script that prints out the command line arguments:
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ command-line-arguments-in-python
Command Line Arguments in Python
June 19, 2023 - For example, calling python arguments-getopt.py -vh is the same as calling python arguments-getopt.py -v -h. So in the last call above, the getopt module thought the user was trying to pass -e as an option, which is invalid. In this article we showed many different methods for retrieving command ...
๐ŸŒ
MachineLearningMastery
machinelearningmastery.com โ€บ home โ€บ blog โ€บ command line arguments for your python script
Command Line Arguments for Your Python Script - MachineLearningMastery.com
June 21, 2022 - Additionally, we may also have compulsory arguments, which we just put into the command line. The part 192.168.0.3:/tmp/ and ./ above are examples. The order of compulsory arguments is important. For example, the rsync command above will copy files from 192.168.0.3:/tmp/ to ./ instead of the other way round. The following replicates the above example in Python using argparse:
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ understanding command line arguments in python
Command Line Arguments in Python: Examples & Tips
July 31, 2025 - Learn through python command line arguments example to manage script inputs efficiently, customize behavior, and boost your Python programming skills.
Address ย  5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
๐ŸŒ
GitBooks
learnbyexample.gitbooks.io โ€บ python-basics โ€บ content โ€บ Command_line_arguments.html
Command line arguments ยท Python Basics
$ ./sum_of_two_numbers.py 2 3 2 + 3 = 5 $ echo $? 0 $ ./sum_of_two_numbers.py 2 3 7 Error: Please provide exactly two numbers as arguments $ echo $? 1 $ ./sum_of_two_numbers.py 2 'x' Traceback (most recent call last): File "./sum_of_two_numbers.py", line 9, in <module> total = int(num1) + int(num2) ValueError: invalid literal for int() with base 10: 'x' $ echo $? 1 ยท #!/usr/bin/python3 import sys, pathlib, subprocess if len(sys.argv) < 2: sys.exit("Error: Please provide atleast one filename as argument") input_files = sys.argv[1:] files_not_found = [] for filename in input_files: if not pathlib.Path(filename).is_file(): files_not_found.append("File '{}' not found".format(filename)) continue line_count = subprocess.getoutput('wc -l < ' + filename) print("{0:40}: {1:4} lines".format(filename, line_count)) print("\n".join(files_not_found))
๐ŸŒ
Embl-community
grp-bio-it-workshops.embl-community.io โ€บ intermediate-python โ€บ 04-argparse โ€บ index.html
Parsing Command Line Arguments โ€“ Intermediate Python
July 24, 2020 - The argv object within the sys module provides a very simple way of accessing the information on the command line: argv is the list that would be returned if the command used to run the program was split by whitespace: ... START ['code/argv_example1.py', 'one', '2', '3.0', 'four,five'] code/argv_example1.py one 2 3.0 four,five END ยท Note about Bash code blocks: we include $ to represent the shell prompt in commands like those above (cat argv_example.py & python argv_example1.py one 2 3.0 four,five).
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ accessing-command-line-arguments-python
Accessing command-line arguments in Python - Python Morsels
August 30, 2021 - Processing sys.argv manually is something that you should only do for very simple Python programs: programs that don't need much complex command-line argument processing and ideally only do this for programs that are just for your use. Let's take a look at another example.