> For the complete documentation index, see [llms.txt](https://stb11816.gitbook.io/python_note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stb11816.gitbook.io/python_note/web/argparse.md).

# argparse

```python
import argparse

# ArgumentParser
parser = argparse.ArgumentParser()
parser.add_argument('-all', action="store_true")
parser.add_argument('-task', help='==> your task')
parser.add_argument('-file', help='==> file path')

args = parser.parse_args()

# 使用 -h 時會顯示 help 內容
```

參考資料：\
<https://medium.com/@dboyliao/python-超好用標準函式庫-argparse-4eab2e9dcc69>

```
設定action="store_true"，表示若使用該參數時則帶入True
#python test.py -c => c是true（觸發）
#python test.py => c是false（無觸發）
```
