How to define multiple variables in single statement

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

    You can define multiple variables like this :

    double a,b,c;
    

    Each variable in one line can also be assigned to specific value too:

    double a=3, b=5.2, c=3.5/3.5;
    

    One more aspect is, while you are preparing common type variable in same line then from right assigned variables you can assign variable on left, for instance :

    int a = 4, b = a+1, c=b*b;
    

    Noticed, you can also practice arithmetic operations on variable by remaining in the same line.

提交回复
热议问题