In line 4 why do we have to add \"=\" after \"-\" ?
num = 5
if num > 2:
print(num)
num -= 1
print(num)
You do not have to do anything, unless you are required to do something for your program to run correctly. Some things are good practice, but don't let anyone or anything but the compiler and the specification convince you that you have to do something one way or another. In this case, n -= 1
is exactly the same as n = n - 1
. Therefore, if you do not wish to put the -
before the =
, then don't. Use n = n - 1
instead.