How does the *= operator work?


#1

Question

How does the *= operator work?

Answer

The *= operator takes the value currently stored in the variable on the left and multiplies it by the value on the right, then stores the result back into that variable. It saves us from having to rewrite the name of the variable on the right side of the =, like this:

my_var = 10
my_var *= 10  # 100

longer = 10
longer = longer * 10  # 100

FAQ: Learn Python - Practice Makes Perfect - product
#2

my_var *= 10 is essentially the same as my_var = my_var * 10

my_var = 10
my_var =  my_var * 10 
or 
my_var  *= 10

it multiplys my_var with number 10 in bouth way