How to define multiple variables in single statement

前端 未结 6 727
青春惊慌失措
青春惊慌失措 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 07:46

    This is not possible, but you also don't need to call parseFile twice.

    Write your code like this:

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

    Python (I believe) supports multiple return values. Java obeys C conventions, and so doesn't permit it. Since that isn't part of the language, the syntax for it isn't either, meaning slightly gross hacks like the temp array are needed if you're doing multiple returns.

提交回复
热议问题