Group a calculation
Quick review (2 minutes)
Four supply kits sit on a table.
When parentheses group an addition, do the addition inside them before multiplying by the number outside. In a calculation with addition and multiplication and no grouping parentheses, Python does the multiplication first.
Write
6 + 3to count the pieces for one kit.Put parentheses around that addition to get
(6 + 3).Put
* 4after the group to count four kits.
Reading 6 + 3 * 4 strictly from left to right would give 36. Python does 3 * 4 first, which counts 12 rings, then adds six clips once, for 18 pieces. To count six clips in every kit, group the two counts as (6 + 3) * 4.
1 In plain words
Four supply kits sit on a table. Each kit needs six clips and three rings. How many pieces do you need for all four kits?
When you calculate with numbers in Python, + means add and * means multiply. The curved marks ( and ) are called parentheses. Read (6 + 3) * 4 as “six clips plus three rings for one kit, four times.” Remember to put parentheses around the counts that go together.
2 Picture it
Four kit trays each contain six filled marks for clips and three open marks for rings. That is nine marks per kit and 36 marks in all.
3 Why
You need the same set of pieces for each kit. Add six clips and three rings to get nine pieces for one kit. Multiplying that nine by four counts one set of pieces for each of the four kits.
4 The rule
When parentheses group an addition, do the addition inside them before multiplying by the number outside.
In a calculation with addition and multiplication and no grouping parentheses, Python does the multiplication first.
5 How
- Write
6 + 3to count the pieces for one kit. - Put parentheses around that addition to get
(6 + 3). - Put
* 4after the group to count four kits.
6 Worked example
Count the pieces in four kits
print((6 + 3) * 4)
print(6 + 3 * 4)
Standard input
Empty
Standard output
36
18
Type both lines into an editor and run the file with Python 3.13. The first line counts all parts of all four kits. The second counts the clips once and the rings four times.
Trace
| Expression | First value | Output | Explanation |
|---|---|---|---|
(6 + 3) * 4 | 6 + 3 = 9 | 36 | Make a kit, then count four kits. Separately, 24 clips plus 12 rings also give 36. |
6 + 3 * 4 | 3 * 4 = 12 | 18 | Without the parentheses, multiply the rings first and count the clips once. |
7 The trap
Reading 6 + 3 * 4 strictly from left to right would give 36. Python does 3 * 4 first, which counts 12 rings, then adds six clips once, for 18 pieces. To count six clips in every kit, group the two counts as (6 + 3) * 4.
Quick checks
Quick check 1 of 2
In 6 + 3 * 4, how many clips and how many rings does Python count?
Show the steps and the answer
6 clips and 12 rings, for 18 pieces.
Why: Python multiplies 3 * 4 first, then adds the six clips once.
Source: Python Software Foundation, An Informal Introduction to Python, 3.1.1. Numbers
Quick check 2 of 2
Three party bags each get seven cards and two stickers. Write a calculation with 3 first and parentheses around the two counts for one bag. How many pieces go in all three bags?
Show the steps and the answer
3 * (7 + 2) gives 27 pieces.
Why: Each bag gets nine pieces. Counting separately also gives 21 cards and 6 stickers, which add up to 27.
Source: Python Software Foundation, An Informal Introduction to Python, 3.1.1. Numbers
Sources
- An Informal Introduction to Python, 3.1.1. Numbers. Python Software Foundation. Python Software Foundation License Version 2. Read 26 Nov 2026.