What does *= do in python?

I think this challenge needs to be updated, the lesson explains that lists can be edited but only explains how to add to a list. Not how to change or remove existing list items.

Also, what does the *= do in the final product since that has not been explained either.

5 Likes

Consider,

a = 6
a = a * 7

What will a be, at this point?

Ok so I think I get what you’re saying now. You’re redefining the variable (a) to be its initial value (6) multiplied by another number (7), so it would be 42.

So instead of repeating the variable (a = a * 7) you can that you want to redefine (=) it and how to do so (*) at the same time.
Would that also work with other operators (+,-,/,%)?

Yes, and exactly the same way (including Bitwise operators). These are a group called assignment operators.

A common mistake is to write the = operator first. It should always be last.

+=
-=
*=
/=
%=
//=
<<=
>>=
4 Likes

3 posts were split to a new topic: Python *= operator