The “action” keyword determines how to handle the command-line arguments.
There are various actions available in Python some of them are:
1. ‘store’ : It stores the value of the arguments.
2. ’store_const’ : It stores the value which is specified by the const keyword argument.
3. ‘store_true’ and ‘store_false’ : These are used to store the value “True” and “False” respectively. These are special cases of ‘store_const’ .
To solve your problem you must use the ‘store_true’ action:
>>> from argparse import ArgumentParser
>>> parser = ArgumentParser()
>>> _ = parser.add_argument('-f', '--file', action='store_true')
>>> args = parser.parse_args()
>>> args.file
False
>>> args = parser.parse_args(['-f'])
>>> args.file
True