What's the difference between "2*2" and "2**2" in Python?

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?


Solution 1:

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.

Solution 2:

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.

Solution 3:

  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