How to define multiple variables in single statement

前端 未结 6 724
青春惊慌失措
青春惊慌失措 2021-01-18 07:14

In Python, I can define two variables with an array in one line.

>>>[a,b] = [1,2]
>>>a
1
>>>b
2

How do I do the

6条回答
  •  没有蜡笔的小新
    2021-01-18 08:00

    If you literaly mean line; as long as you place a semicolon in between two statements, they are executed as if there is a new line in between so you can call:

    a = 1; b = 2;
    

    You can even compress an entire file into a oneliner, by removing comment (that scope to the end of the line). Spacing (space, tab, new line,...) is in general removed from the Java files (in memory) as first step in the Java compiler.

    But you are probably more interested in a singe statement. Sytax like [start, stop] = parseFile(file); is not supported (at least not for now). You can make a onliner:

    int[] data = parseFile(file); start = data[0]; stop = data[1];
    

提交回复
热议问题