VOOZH about

URL: https://www.geeksforgeeks.org/python/argparse-way-to-include-default-values-in-help/

⇱ Argparse: Way to include default values in '--help'? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Argparse: Way to include default values in '--help'?

Last Updated : 23 Jul, 2025

Argparse in Python allows you to create user-friendly command-line interfaces. By including default values in the --help output, you can make your script's behavior more transparent. There are several ways to achieve this, including using argparse.ArgumentDefaultsHelpFormatter and custom help formatters.

Include default values in '--help'

Below are the ways to include default values in '--help' in Python.

  • Using argparse.ArgumentDefaultsHelpFormatter
  • Using Custom Help Formatter

Include default values in '--help' Using argparse.ArgumentDefaultsHelpFormatter

In this example, we are using argparse.ArgumentDefaultsHelpFormatter to automatically include the default values of the arguments in the --help output. This makes it clear to users what the defaults are for --course, --duration, and --level options.

Output:

👁 EX1

Include default values in '--help' Using Custom Help Formatter

In this example, we are using a custom help formatter by subclassing argparse.HelpFormatter to include default values in the help message. The _get_help_string method is overridden to append the default value to each argument's help text, providing clarity on what defaults are used.

Output:

👁 Ex2
Comment
Article Tags: