What is the difference between the following codes?
code1:
var=2**2*3
code2:
var2=2*2*3
I see no difference. This raises the following question.
Why is the code1 used if we can use code2?
*= Multiply AND. It multiplies right operand with the left operand and assign the result to left operand. c *= a is equivalent to c = c * a. /= Divide AND. It divides left operand with the right operand and assign the result to left operand.
There is no difference at runtime. The only difference between the two types of quotes is the one you have already pointed out: Single quotes need to be escaped inside single quoted string literals but not inside double-quoted string literals.
For numeric data types double asterisk (**) is defined as exponentiation operator >>> a=10; b=2 >>> a**b 100 >>> a=1.5; b=2.5 >>> a**b 2.7556759606310752 >>> a=3+2j >>> b=3+5j >>> a**b (-0.7851059645317211+2.350232331971346j)
i+=1 does the same as i=i+1 there both incrementing the current value of i by 1. Do you mean "i += 1"? If so, then there's no difference.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With