Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Python Fundamentals

Lesson 45 of 55 · Python

Building a CLI with argparse

Duration: 20 minutes

Building a CLI with argparse\n\nThe argparse module makes it easy to write user‑friendly command‑line interfaces. It automatically generates help messages and parses arguments for you.\n\npython\nimport argparse\n\nparser = argparse.ArgumentParser(description='Simple greeter')\nparser.add_argument('name', help='Name to greet')\nparser.add_argument('-n', '--times', type=int, default=1, help='Number of repetitions')\nargs = parser.parse_args()\n\nfor _ in range(args.times):\n print(f'Hello, {args.name}!')\n\n\nRun the script from a terminal: python greet.py Alice -n 3.\n

Previous: MultiprocessingNext: Introduction to Flask Web Framework