Fork me on GitHub

Argparse中action的可选参数store_true,store_false

store_true 是指带触发action时为真,不触发则为假, 代码去掉default初始化,其功能也不会变化

 

parser.add_argument('-c', action='store_true')
# 或者parser.add_argument('-c', action='store_true', default=false) #python test.py -c => c是true(触发) #python test.py => c是false(无触发)

  

 

posted @ 2021-04-15 14:30  stardsd  阅读(1473)  评论(0编辑  收藏  举报