Devnote

Web Development Blog Company, Services India

MySQL Error 121 Duplicate key on write - Practical Repair Strategy
MySQL Error 121 Duplicate key on write – Practical Repair Strategy
February 13, 2026
PHP cURL error 60: SSL certificate problem - Windows & Linux Fix
PHP cURL error 60: SSL certificate problem – Windows & Linux Fix
February 11, 2026
Fix localhost refused to connect After Installing XAMPP / WAMP
Fix “localhost refused to connect” After Installing XAMPP / WAMP
February 9, 2026
Composer Error Memory exhausted When Installing Packages - Real Fix
Composer Error: Memory exhausted When Installing Packages – Real Fix
February 6, 2026
MySQL 8 Error Unknown collation: utf8mb4_0900_ai_ci - Safe Migration Guide
MySQL 8 Error Unknown collation: utf8mb4_0900_ai_ci – Safe Migration Guide
February 4, 2026
Devnote

Type and hit Enter to search

  • Home
  • Laravel
    • Auth
    • Migration
    • DATATABLE
    • Yajra
  • wordpress
    • plugin
    • WPBakery
    • woocommerce
  • PHP
    • MYSQL
    • Ajax
  • Blog
  • Informational
    • About us
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
  • Contact US
Devnote
  • Home
  • Laravel
    • Auth
    • Migration
    • DATATABLE
    • Yajra
  • wordpress
    • plugin
    • WPBakery
    • woocommerce
  • PHP
    • MYSQL
    • Ajax
  • Blog
  • Informational
    • About us
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
  • Contact US
Command line arguments

Command line arguments in Python

Image
Devnote team
November 11, 2020
One Min Read
789 Views
0 Comments

This tutorial is Command line arguments in Python. Python is a popular programming language, as well as having support for most operating systems. Python users use specific commands, set options, and more. these options could tell the tool to output additional information, like read data from a specified source, or send output to a certain location.

CLI(Command Line Input) tools arguments are passed differently, depending on your operating system:

Unix-like: – followed by a letter, like -h , or — followed by a word, like –help

Windows: / followed by either a letter, or word, like /help.

handle Command line arguments with Python

Python 3 supports a number of different ways to handle command-line arguments. The Python built-in way is to use the sys module.

sys Module

The sys module implements (System-specific parameters and functions) the command line arguments in a simple list structure named sys.argv.

Example

# first-arguments.py

import sys
print ("The First argument is {}".format(sys.argv[0]))

Save this code in a named first-arguments.py.

Run

$ python3 first-arguments.py

The First argument is first-arguments.py

Count the Number of Arguments

We count the number of command-line arguments using the built-in len() method. The actual number of arguments passed by the user is len(sys.argv) – 1.

Example

# arguments-count.py

import sys
# Count the arguments
arguments = len(sys.argv) - 1

print ("Count argument {}".format(arguments))

Save this code in a named arguments-count.py.

Run

$ python3 arguments-count.py
Count argument 0

$ python3 arguments-count.py --help me
Count argument 2

$ python arguments-count.py --option "long string"
Count argument 2

Categories:

CMDpython

Other Articles

create function in python
Previous

How to create a function in python

Python logical operators
Next

Python logical operators

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

How to connect MySQL from the windows command line

How to connect MySQL from the windows command line

April 1, 2021
How to add a date filter to Django admin?

How to add a date filter to Django admin?

February 1, 2021
How to remove default apps in Django admin?

How to remove default apps in Django admin?

January 29, 2021
Remove an item from a list in Python

How to remove an item from a list in Python

January 28, 2021
Devnote

Devnote provides a collection of tutorials about PHP, Laravel, WordPress, Django, MySQL, Bootstrap, Jquery, Ajax, APIs, CRUD operations, etc.

Devnote © , All Rights Reserved.

Page Links

  • Home
  • About us
  • Blog
  • Contact US
  • Site map

Category

  • PHP
  • Laravel
  • wordpress
  • HTML
  • jQuery

Follow Us

Facebook Instagram Twitter Youtube Linkedin Pinterest
Morbi, Gujarat, India - 363641
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT
Advertisement