Pythonでプログラム実行時に引数を渡す

2020年12月21日

Pythonでプログラム実行時に引数を渡す

参考:Python: コマンドライン引数とは?(超基礎)

プログラム


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

args = sys.argv

print(args)
print("第1引数:" + args[1])
print("第2引数:" + args[2])
print("第3引数:" + args[3])

実行結果


$ python test_argv.py  ichiro jiro saburo
['test_argv.py', 'ichiro', 'jiro', 'saburo']
第1引数:ichiro
第2引数:jiro
第3引数:saburo
YouTube

2020年12月21日