TUPLE ASSIGNMENT TRB CSI › Python Programming › tuple assignment

TUPLE ASSIGNMENT

Tuple Assignment என்பது Python-ல் multiple variables-க்கு multiple values-ஐ ஒரே statement-ல் assign செய்வது. Simple-ah: a, b = 10, 20 இதில்: a = 10 b = 20 என்று இரண்டு தனித்தனி assignment எழுதாமல், ஒரே line-ல் assign செய்கிறோம்.

Premium — locked Advanced 14 min 107 cards 12 programs 7 MCQs v3
This is a premium lesson. You can see the shape of every card — unlock to read them. Unlock

TUPLE ASSIGNMENT - Python…

Premium This card is part of the premium lesson. Unlock
Definition

Tuple Assignment என்பது Python-ல் multiple variables-க்கு multiple values-ஐ ஒரே statement-……

Premium This card is part of the premium lesson. Unlock
Simple Explanation

Normal assignment: a = 10 b = 20 c = 30 Tuple assignment: a, b, c = 10, 20, 30 இரண்டின் final re……

Premium This card is part of the premium lesson. Unlock
Concept
Important concept

Python-ல்: a, b = 10, 20 என்பதை internally conceptually: (a, b) = (10, 20) என்று புரிந்துகொள்ளலாம். Right sid……

Premium This card is part of the premium lesson. Unlock
Explanation
Packing

Multiple values-ஐ ஒரு tuple-ஆ……

Premium This card is part of the premium lesson. Unlock
Program
Example

இங்கு: 10, 20, 30 automatic-ah ஒரு tup……

Premium This card is part of the premium lesson. Unlock
Explanation
Unpacking

Tuple-ல் இருக்கும் values-ஐ individual variables-க்கு பிரித்த……

Premium This card is part of the premium lesson. Unlock

Mapping: data = (10, 20, 30) ……

Premium This card is part of the premium lesson. Unlock
Explanation
Tuple assignment

Packing + Unpacking இரண்டு operations-உம் ஒரே statement-ல் நடக்கலாம். a, b, c = 10, 20, 30 Conceptually: Step……

Premium This card is part of the premium lesson. Unlock
Explanation

name, age, mark = "Raja", 20,……

Premium This card is part of the premium lesson. Unlock
Explanation

name, age, mark = "Raja", 20, 85 Right side: "Raja", 20, 85 3 values. Left side: name, age, m……

Premium This card is part of the premium lesson. Unlock
Important
Most important rule

Variables count மற்றும் values count normally equal-ஆக இருக்க வேண்ட……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error

ValueError: too many values to ……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error

ValueError: not enough values……

Premium This card is part of the premium lesson. Unlock
Explanation
Swapping

Tuple assignment-ன் மிக முக்கியமான use: Two variables values swap செய்வது. Supp……

Premium This card is part of the premium lesson. Unlock
Dry Run
Swapping dry run
Comparison
Other languages vs python

Traditional method: temp = a a = b b = te……

Premium This card is part of the premium lesson. Unlock
Explanation
Multiple data types

Tuple assignment-ல் same datatype மட்டும் இருக்க வேண்டும் என்ற rule இல்லை. name, age, percentage……

Premium This card is part of the premium lesson. Unlock
Explanation
Parentheses

Tuple assignment-க்கு parentheses compulsory இ……

Premium This card is part of the premium lesson. Unlock
Important

Python tuple உருவாவதற்கு main……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation
List unpacking

பெயர் tuple assignment என்று commonly சொல்லப்பட்டாலும், unp……

Premium This card is part of the premium lesson. Unlock

Because iterable values seque……

Premium This card is part of the premium lesson. Unlock
Explanation
String unpacking

String characters-யும் unpack செ……

Premium This card is part of the premium lesson. Unlock

Because "ABC" contains exactl……

Premium This card is part of the premium lesson. Unlock
Explanation
Range unpacking

a, b, c = range(3) print(a, b……

Premium This card is part of the premium lesson. Unlock
Program
Because

produces: 0, 1, 2…

Premium This card is part of the premium lesson. Unlock
Explanation
Starred unpacking

Sometimes variables count and values count equal இருக்க வேண்டி……

Premium This card is part of the premium lesson. Unlock
Output
Result
Explanation
Program

a, *b = 10, 20, 30, 40…

Premium This card is part of the premium lesson. Unlock
Important

Starred variable result list ……

Premium This card is part of the premium lesson. Unlock
Explanation
Star at end

a, b, *c = 10, 20, 30, 40, 50…

Premium This card is part of the premium lesson. Unlock
Output
Result
Explanation
Star at beginning

*a, b = 10, 20, 30, 40…

Premium This card is part of the premium lesson. Unlock
Output
Result
Explanation
Star in middle

a, *b, c = 10, 20, 30, 40, 50…

Premium This card is part of the premium lesson. Unlock
Output
Result

Visualization: 10 20 30 40 50……

Premium This card is part of the premium lesson. Unlock
Explanation
Ignore value

Sometimes ஒரு value தேவையில்லை. Conventionally……

Premium This card is part of the premium lesson. Unlock

Here age value 20 intentionally ignore செய்கிறோம். _ என்பது magic keyword இல்லை. இது ……

Premium This card is part of the premium lesson. Unlock
Explanation
Function return

Tuple assignment functions-ல் மிகவும் useful. Function:……

Premium This card is part of the premium lesson. Unlock

Function multiple values return செய்வது போலத் தோன்றினாலும்: return……

Premium This card is part of the premium lesson. Unlock
Explanation
Nested unpacking

Nested tuple-களையும் unpack செய்யலா……

Premium This card is part of the premium lesson. Unlock

Mapping: a ← 10 (b, c) ← (20,……

Premium This card is part of the premium lesson. Unlock
Explanation
For loop use

Tuple unpacking for loop-ல் மிக common. students = [ ("……

Premium This card is part of the premium lesson. Unlock

Each iteration: ("Arun", 80) ……

Premium This card is part of the premium lesson. Unlock
Explanation
Dictionary use

Dictionary .items() உடன் tuple unpacking மிகவும் important. ……

Premium This card is part of the premium lesson. Unlock

student.items() each time: ("name", "Raja") ("ma……

Premium This card is part of the premium lesson. Unlock
Comparison
Difference
Common Mistake
Common error 1

a, b = 10 Wrong. Because 10 is……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 2

a, b = [10, 20, 30]…

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error

ValueError: too many values t……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 3

a, b, c = [10, 20]…

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error

ValueError: not enough values……

Premium This card is part of the premium lesson. Unlock
Remember

a = 10, 20 does NOT assign a = 10 and something e……

Premium This card is part of the premium lesson. Unlock
Program
Example
Important

Tuple assignment பற்றி நினைவில் வைத்திருக்க வேண்டிய முக்கிய points: Multiple variables can be assigned in one……

Premium This card is part of the premium lesson. Unlock
Memory Trick

இந்த line மட்டும் நினைவில் வைத்த……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

a, b, c = 10, 20, 30 Think: 1……

Premium This card is part of the premium lesson. Unlock
TRB Point

TRB / NET / SET / interview MCQ-ல் freque……

Premium This card is part of the premium lesson. Unlock

Reason: Right-hand side is evalua……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question

x = 10, 20 print(type(x)) Answer: R……

Premium This card is part of the premium lesson. Unlock
TRB Point
Trb point 3

a, *b, c = 1, 2, 3, 4, 5…

Premium This card is part of the premium lesson. Unlock
Output
Result
Remember

Starred variable always colle……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question

Why does this work? a, b = b, a Answer: Python first evaluates the right-hand……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the output? a, b = 5,……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the output? a, b = 10……

Premium This card is part of the premium lesson. Unlock
MCQ

What happens? a, b = 10, 20, ……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the output? x = 1, 2,……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the value of b? a, *b……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the output? a, b, c =……

Premium This card is part of the premium lesson. Unlock
MCQ

Which symbol is mainly respon……

Premium This card is part of the premium lesson. Unlock
Practice

Predict the output: x, y, z = 100, 200, 300 print(y) Predict: a, b = 5, 7 a, b = b, a print……

Premium This card is part of the premium lesson. Unlock
Summary

Tuple Assignment என்பது Python-ல் multiple values-ஐ ……

Premium This card is part of the premium lesson. Unlock
Concept

Right side → Packing Left side → Unpacking Most important application: a, ……

Premium This card is part of the premium lesson. Unlock
Output
Result

One-line exam memory: Tuple Assignme……

Premium This card is part of the premium lesson. Unlock
Text size
17px
Theme
Contents
Print / PDF
Program