Skip to content

Instantly share code, notes, and snippets.

@demetranadya
Created November 19, 2023 05:52
Show Gist options
  • Save demetranadya/21bd3cf6eaee79ab7976e65b3c9cc592 to your computer and use it in GitHub Desktop.
Save demetranadya/21bd3cf6eaee79ab7976e65b3c9cc592 to your computer and use it in GitHub Desktop.
python args
# Задание
# Напишите скрипт, который принимает любое кол-во параметров через произвольное количество пробелов в качестве аргументов и выводит их в той же последовательности на экран, каждый на отдельной строке.
# В случае отсутствия параметров скрипт должен выводить «no args».
# Пример 1
# Ввод Вывод
# python3 solution.py 5 string 1
# 5
# string
# 1
# Пример 2
# Ввод Вывод
# python3 solution.py
# no args
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('arg', nargs='*')
print(parser)
print("-----")
args = parser.parse_args()
print(args)
if len(args.arg) == 0:
print("no args")
for i in args.arg:
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment