Editor settings

General settings

Save settings

Learn to program with Python

Decrease the value of a variable #

Compound subtraction is a shorthand way of subtracting a value from a variable and then assigning the result back to the variable. It is achieved by using the -= operator.

For example:

x = 20
x -= 1 # equivalent to x = x - 1
print(x) # output: 19

Exercise #

  • Rewrite the code on line 3 to use -= to increase the value of x by 1
  • Value of x should be 19
Output will be displayed here