首页 > 编程语言 > 详细

[JAVA/PYTHON] Command Line Argument | String[] args | sys.argv

时间:2020-05-27 00:32:30      阅读:58      评论:0      收藏:0      [点我收藏+]

 

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!