dig = int(input())
a = 1
while dig > 0:
a = a * dig % 10
dig = dig // 10
print(a)
2 variant
dig = int(input())
a = 1
while dig > 0:
a *= dig % 10
dig = dig // 10
print(a)
What’s the difference? why is the code executed differently, even though the syntax is the same
dig = 415
first variant answer 0
second variant answer 20
The *= operator (and its friends +=, -=, /=, etc.) are called augmented assignments, which is a type of syntactic sugar, yes. You still need to be careful with operator precedence. For all augmented assignments, the precedence is:
# These are equivalent:
a += x
a = a + (x)
# As are these:
a *= x
a = a * (x)
where x can be a single variable or an expression, as in your case.