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

2021-01-07 13:29

阅读:507

标签:span   ble   ++   ack   cond   system   amp   com   pre   

 

JAVA

public class Args
{
    public static void main(String[] args)
    {
        // for (String arg : args)
        //     System.out.println(arg);
        //或者下面的遍历方法
        for (int i = 0; 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) = list>
scriptName = Sys.py
jerry
elaine
george
kramer

Sys.py
jerry
elaine
george
kramer

 

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

标签:span   ble   ++   ack   cond   system   amp   com   pre   

原文地址:https://www.cnblogs.com/profesor/p/12969597.html


评论


亲,登录后才可以留言!