⊗pyPmBsShO 10 of 208 menu

Shortcuts in Python

There are cases when mathematical operations take up a lot of space in the code. For example, let's add 1 to a variable:

num = 1 num = num + 1 # add 1 to variable num print(num) # 2

This code can be rewritten in a shortened form using the operator +=:

num = 1 num += 1 # add the number 1 to the variable num print(num) # 2

In this way, you can also subtract a number from a variable:

num = 1 num -= 1 # subtract the number 1 from the variable num print(num) # 0

Rework this code so that it has increment and decrement operations:

num = 4 num = num + 1 num = num - 1 num = num + 1
azbydeenesfrkakkptruuz