Get number of arguments with len (sys.argv) – python

environment

  • python
  • len(sys.argv)

Thing you want to do

The details are boring, but you can pass arguments when you run python on the command line. It is a program that obtains the number of arguments.

Implementation

# -*- coding: utf-8 -*-
import sys

if __name__=='__main__':

    num = len(sys.argv)
    count = 1

while count < num:
    print sys.argv[count]
    count += 1
藤沢瞭介(Ryosuke Hujisawa)
  • りょすけと申します。18歳からプログラミングをはじめ、今はフロントエンドでReactを書いたり、AIの勉強を頑張っています。off.tokyoでは、ハイテクやガジェット、それからプログラミングに関する情報まで、エンジニアに役立つ情報を日々発信しています!

未整理記事