JAVA
public class Args { public static void main(String[] args) { // for (String arg : args) // System.out.println(arg); //或者下面的遍历方法 for (int i = 0; i < args.length; i++) System.out.println(args[i]); } }
terminal输入:
javac Args.java && java Args jerry elaine george kramer
输出结果:
jerry
elaine
george
kramer
PYTHON
sys.argv
Argument varible
import sys # unpacking scriptName, first, second, third, fourth = sys.argv
print("type(sys.argv) = " + str(type(sys.argv))) #可以看出sys.argv的类型就是个list print("scriptName = " + scriptName) print(first) print(second) print(third) print(fourth) print()
#遍历列表 for item in sys.argv: print(item)
terminal 中输入:
python3 Sys.py jerry elaine george kramer
输出结果
type(sys.argv) = <class ‘list‘> scriptName = Sys.py jerry elaine george kramer Sys.py jerry elaine george kramer
[JAVA/PYTHON] Command Line Argument | String[] args | sys.argv
原文:https://www.cnblogs.com/profesor/p/12969597.html