⊗pyPmBsMOPa 13 of 208 menu

Grouping Brackets in Python

If you want, you can specify the priority of operations using parentheses. For example, let's rework our code so that addition is performed first, and then multiplication:

res = 2 * (2 + 3) print(res) # 10 (result 2 * 5)

There can be any number of brackets, including those nested within each other:

res = 2 * (2 + 4 * (3 + 1)) print(res) # 36

The following code is given:

res = (2 + 3) * 4 print(res)

Tell me what will be output to the console.

The following code is given:

res = (10 - 6) / 3 print(res)

Tell me what will be output to the console.

The following code is given:

res = 10 - 6 * (3 - 5) print(res)

Tell me what will be output to the console.

The following code is given:

res = 4 - 1 + (5 + 6 * (2 + 7)) print(res)

Tell me what will be output to the console.

byenru