How to define multiple variables in single statement

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

    Maybe this is what you're looking for:

    int array[] = {1,2};
    

    Java array assignment (multiple values)

    If you're looking to explicitly assign to each element, I don't think you can do that within one assignment, as a similar concept with the 2-d example below. Which seems like what you want as Jeremy's answers specifies.

    Explicitly assigning values to a 2D Array?

提交回复
热议问题