How to convert command-line arguments to specific types in Python

Florian Dahlitz
7 min
Aug. 3, 2021

In this argparse tutorial, you'll learn how to convert command-line arguments to specific types in Python.

First, I'll show you the default behaviour converning types of the argparse's module argument parser.

Then, you'll see how you can use the type-parameter to pass built-in functions to the command-line parser to convert arguments.

Lastly, we'll see that any callable can be supplied to the type-parameter and how you can benefit from it.