Menu
Coddy logo textTech

Arithmetic Shortcuts

Part of the Fundamentals section of Coddy's Python journey — lesson 12 of 77.

Python created a cool shortcut for self-arithmetic operations.

For example, instead of writing:

a = 5
a = a + 3 # a holds 8

We can simplify it by writing +=:

a = 5
a += 3 # a holds 8

The += operator adds the value 3 to a.

This operation is valid for all arithmetic operations:

OperatorShortcut
++=
--=
**=
//=
%%=
challenge icon

Challenge

Beginner

You are given a code with initialization of count. (Don't delete this line!)

Your task is to add the following operations, in this order:

  1. Add 4 to count
  2. Multiply count by 2
  3. Subtract 1 from count

Use the arithmetic shortcuts to do so!

Cheat sheet

Python provides shortcuts for self-arithmetic operations:

Operation Shortcut Example
Addition += a += 3 (equivalent to a = a + 3)
Subtraction -= a -= 3
Multiplication *= a *= 3
Division /= a /= 3
Modulus %= a %= 3

Try it yourself

# Type your code below
count = 0

# Don't change the line below
print(f"count = {count}")
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals