What is the difference between the following codes?
以下代码有什么不同?
code1:
code1:
var=2**2*3
code2:
code2:
var2=2*2*3
I see no difference. This raises the following question.
我看到没有区别。这就提出了以下问题。
Why is the code1 used if we can use code2?
如果我们可以使用code2,为什么要使用code1 ?
10 个解决方案
#1
115
Try:
试一试:
2**3*2
and
和
2*3*2
to see the difference.
看到差别。
**
is the operator for "power of". In your particular operation, 2 to the power of 2 yields the same as 2 times 2.
**是“权力”的操作者。在特定的操作中,2的2次方等于2乘以2。
#2
32
Double stars (**
) are exponentiation. So "2 times 2" and "2 to the power 2" are the same. Change the numbers and you'll see a difference.
双星是指数。所以2乘以2和2的2次方是一样的。改变数字,你就会看到不同。
#3
14
2**2 means 2 squared (2^2)
2*2 mean 2 times 2 (2x2)
In this case they happen to have the same value, but...
在这种情况下,它们碰巧具有相同的值,但是…
3**3*4 != 3*3*4
#4
4
To specifically answer your question Why is the code1 used if we can use code2? I might suggest that the programmer was thinking in a mathematically broader sense. Specifically, perhaps the broader equation is a power equation, and the fact that both first numbers are "2" is more coincidence than mathematical reality. I'd want to make sure that the broader context of the code supports it being
要明确地回答你的问题,如果我们可以使用code2,为什么要使用code1 ?我可能会说,程序员是在从数学的更广泛的意义上思考。具体来说,或许更广泛的方程是一个幂函数方程,而第一个数字都是“2”这一事实与其说是数学事实,不如说是巧合。我希望确保更广泛的代码上下文支持它
var = x * x * y
in all cases, rather than in this specific case alone. This could get you in big trouble if x is anything but 2.
#6
2
2**2 = 2 power-of 2
2**2 = 2次方- 2
2*2 = 2 times 2
2*2 = 2*2。
#7
2
The **
operator in Python is really "power;" that is, 2**3 = 8
.
Python中的**操作符是真正的“power”,即2**3 = 8。
#8
1
The top one is a "power" operator, so in this case it is the same as 2 * 2 equal to is 2 to the power of 2. If you put a 3 in the middle position, you will see a difference.
最上面的是一个“幂”运算符,所以在这种情况下它等于2 * 2等于2的2次方。如果你把3放在中间,你会看到不同。
#9
1
A double asterisk means to the power of. A single asterisk means multiplied by. 22 is the same as 2x2 which is why both answers came out as 4.
双星号表示的是。一个星号表示乘以。22和2x2是一样的所以两个答案都是4。
#10
1
Power has more precedence than multiply, so:
权力比多重更重要,所以:
2**2*3 = (2^2)*3
2*2*3 = 2*2*3
#1
115
Try:
试一试:
2**3*2
and
和
2*3*2
to see the difference.
看到差别。
**
is the operator for "power of". In your particular operation, 2 to the power of 2 yields the same as 2 times 2.
**是“权力”的操作者。在特定的操作中,2的2次方等于2乘以2。
#2
32
Double stars (**
) are exponentiation. So "2 times 2" and "2 to the power 2" are the same. Change the numbers and you'll see a difference.
双星是指数。所以2乘以2和2的2次方是一样的。改变数字,你就会看到不同。
#3
14
2**2 means 2 squared (2^2)
2*2 mean 2 times 2 (2x2)
In this case they happen to have the same value, but...
在这种情况下,它们碰巧具有相同的值,但是…
3**3*4 != 3*3*4
#4
4
To specifically answer your question Why is the code1 used if we can use code2? I might suggest that the programmer was thinking in a mathematically broader sense. Specifically, perhaps the broader equation is a power equation, and the fact that both first numbers are "2" is more coincidence than mathematical reality. I'd want to make sure that the broader context of the code supports it being
要明确地回答你的问题,如果我们可以使用code2,为什么要使用code1 ?我可能会说,程序员是在从数学的更广泛的意义上思考。具体来说,或许更广泛的方程是一个幂函数方程,而第一个数字都是“2”这一事实与其说是数学事实,不如说是巧合。我希望确保更广泛的代码上下文支持它
var = x * x * y
in all cases, rather than in this specific case alone. This could get you in big trouble if x is anything but 2.
#5
#6
2
2**2 = 2 power-of 2
2**2 = 2次方- 2
2*2 = 2 times 2
2*2 = 2*2。
#7
2
The **
operator in Python is really "power;" that is, 2**3 = 8
.
Python中的**操作符是真正的“power”,即2**3 = 8。
#8
1
The top one is a "power" operator, so in this case it is the same as 2 * 2 equal to is 2 to the power of 2. If you put a 3 in the middle position, you will see a difference.
最上面的是一个“幂”运算符,所以在这种情况下它等于2 * 2等于2的2次方。如果你把3放在中间,你会看到不同。
#9
1
A double asterisk means to the power of. A single asterisk means multiplied by. 22 is the same as 2x2 which is why both answers came out as 4.
双星号表示的是。一个星号表示乘以。22和2x2是一样的所以两个答案都是4。
#10
1
Power has more precedence than multiply, so:
权力比多重更重要,所以:
2**2*3 = (2^2)*3
2*2*3 = 2*2*3