sys.argv is a parameter acquired from an external bridge program
1.t1.py
import sys a = sys.argv b = len(sys.argv) print(a) print(b)
In the python terminal typing python t1.py zhang kang run this script, and into the parameters
The output is:
[ 'T1.py', 'zhang', 'kang']
2.t2.py
import sys a = sys.argv[0] b = sys.argv[1] c = sys.argv[2] print("filename:",a) print("param1:",b) print("param2:",c)
In the python terminal typing python t2.py zhang kang run this script, and into the parameters
The output is:
filename: t2.py
param1: zhang
param2: kang
3.sys.argv [1:] it represents?
This is a slicing
sys.argv parameter passed is a program, you can think of it a list, sys.argv [1:] 1 is to extract the parameters passed back variable.
Such as: test.py 'aaa' 'bbb' 'ccc' 'ddd'
The sys.argv [1:] values represent [ 'bbb', 'ccc', 'ddd']