Introduction to Python: where it came from, what it's used for, lists and argparse

Python is a high-level, interpreted, dynamically typed language. Guido van Rossum first released it in February 1991 (version 0.9.0). The name comes from the comedy series Monty Python’s Flying Circus, not the snake. Its design favours readability: indentation marks code blocks, and the standard library covers a lot without extra installs.
Van Rossum based Python on ABC, a teaching language he had worked on at CWI in the Netherlands. He kept ABC’s readability and added things ABC lacked, such as exceptions, modules and access to the operating system. Python 2 reached end of life on 1 January 2020, so anything new should use Python 3.
What Python is used for
Section titled “What Python is used for”- Web back ends: Django and Flask, plus FastAPI for APIs.
- Data analysis and scientific computing: NumPy, pandas, SciPy and Matplotlib.
- Machine learning: PyTorch, TensorFlow and scikit-learn. The heavy computation runs in C/C++/CUDA underneath, and Python is the interface.
- Automation and scripting: system administration, DevOps tooling, and glue code between other programs.
- Finance: data analysis with pandas, and quantitative libraries such as QuantLib, a C++ library with Python bindings.
- Simple games: 2D games with Pygame.
The common thread is a large ecosystem of packages on PyPI and a low barrier to getting something working.
A list is an ordered, mutable collection written with square brackets. Items can be of any type, including other lists.
fruits = ["apple", "banana", "cherry"]print(fruits) # ['apple', 'banana', 'cherry']
print(fruits[0]) # 'apple', since indexes start at 0print(fruits[-1]) # 'cherry', since negative indexes count from the endprint(fruits[0:2]) # ['apple', 'banana'], a slice that excludes the end index
fruits.append("date") # add to the endfruits.remove("banana") # remove the first matching valuefruits.sort(reverse=True) # sort in placeprint(fruits, len(fruits)) # ['date', 'cherry', 'apple'] 3
more = fruits + ["elderberry"] # concatenation creates a new listlist.sort() changes the list in place and returns None. sorted(fruits) returns a new sorted list and leaves the original alone. Mixing the two up is a common beginner bug.
Command-line arguments with argparse
Section titled “Command-line arguments with argparse”The standard-library argparse module parses command-line options and validates their types. It also generates --help output for you.
import argparse
parser = argparse.ArgumentParser(description="Example argparse script.")parser.add_argument("-n", "--name", required=True, help="your name")parser.add_argument("-a", "--age", type=int, help="your age")
args = parser.parse_args()
print("Hello,", args.name)if args.age is not None: print("Your age is", args.age)Save it as example.py and run it:
$ python example.py -n Alice -a 30Hello, AliceYour age is 30How it works:
ArgumentParser(description=...)creates the parser. The description appears inpython example.py --help.add_argumentdeclares each option. Options are optional unless you passrequired=True. An option that isn’t given isNone, unless you setdefault=.type=intconverts the value. Passing-a thirtymakes argparse exit with an error message instead of crashing later.parse_args()readssys.argvand returns a namespace. The long option name becomes the attribute name, so--agebecomesargs.age.
The argparse tutorial covers positional arguments, flags (action="store_true"), choices and subcommands.
References
Section titled “References”© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)