Skip to content
Worked Examples · Example 10.3

Q.Example 10.3: Tuple assignment with an expression on the right side — (num3,num4) = (10+5,20+5) evaluates the expressions first, assigning 15 to num3 and 25 to num4.

Tripura TbseTextbookSubjective· 2mImportance★★★★★est
17% · 5/30 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

In (num3, num4) = (10 + 5, 20 + 5) Python first evaluates the right-hand expressions to (15, 25) and then assigns positionally — num3 = 15, num4 = 25.

The idea. Tuple assignment follows the universal assignment rule: the entire right-hand side is evaluated before any name is bound. So arithmetic (or any expression — function calls, slices, comparisons) on the right is reduced to plain values, packed into a tuple, and unpacked position by position into the left-side variables.

Program:

(num3, num4) = (10 + 5, 20 + 5)    # right side expressions are evaluated first
print("num3:", num3)
print("num4:", num4)

Verified output:

num3: 15
num4: 25

Step by step:

StepWhat Python doesResult
1Evaluate 10 + 515
2Evaluate 20 + 525

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.