sys.argv Python

To передать аргументы в Python скрипт из командной строки нужно воспользоваться библиотекой sys

import sys

Далее каждый аргумент нужно принимать с помощью sys.argv

a = sys.argv[1]

Пример: скрипт add.py

import sys first = sys.argv[1] second = sys.argv[2] print(f"{first} + {second} = {first + second}")

python3 add.py top bicycle

top + bicycle = topbicycle

To проделать то же самое с целыми числами - используем функцию int

import sys first = int(sys.argv[1]) second = int(sys.argv[2]) print(f"{first} + {second} = {first + second}")

python3 add.py 3 4

3 + 4 = 7

В других языках

В C аналогичную функцию выполняет int argc, char* argv[]

В Bash это встроено по умолчанию .

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: