[JAVA/PYTHON] Command Line Argument | String[] args | sys.argv
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.argvprint("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
相关推荐
Lzs 2020-10-23
聚合室 2020-11-16
零 2020-09-18
Justhavefun 2020-10-22
jacktangj 2020-10-14
ChaITSimpleLove 2020-10-06
Andrea0 2020-09-18
周游列国之仕子 2020-09-15
afanti 2020-09-16
88234852 2020-09-15
YClimb 2020-09-15
风雨断肠人 2020-09-04
卖口粥湛蓝的天空 2020-09-15
stulen 2020-09-15
pythonxuexi 2020-09-06
abfdada 2020-08-26
梦的天空 2020-08-25