TUPLE ASSIGNMENT - Python…
TUPLE ASSIGNMENT
Tuple Assignment என்பது Python-ல் multiple variables-க்கு multiple values-ஐ ஒரே statement-ல் assign செய்வது. Simple-ah: a, b = 10, 20 இதில்: a = 10 b = 20 என்று இரண்டு தனித்தனி assignment எழுதாமல், ஒரே line-ல் assign செய்கிறோம்.
Tuple Assignment என்பது Python-ல் multiple variables-க்கு multiple values-ஐ ஒரே statement-……
Normal assignment: a = 10 b = 20 c = 30 Tuple assignment: a, b, c = 10, 20, 30 இரண்டின் final re……
Python-ல்: a, b = 10, 20 என்பதை internally conceptually: (a, b) = (10, 20) என்று புரிந்துகொள்ளலாம். Right sid……
Multiple values-ஐ ஒரு tuple-ஆ……
இங்கு: 10, 20, 30 automatic-ah ஒரு tup……
Tuple-ல் இருக்கும் values-ஐ individual variables-க்கு பிரித்த……
Mapping: data = (10, 20, 30) ……
Packing + Unpacking இரண்டு operations-உம் ஒரே statement-ல் நடக்கலாம். a, b, c = 10, 20, 30 Conceptually: Step……
name, age, mark = "Raja", 20,……
name, age, mark = "Raja", 20, 85 Right side: "Raja", 20, 85 3 values. Left side: name, age, m……
Variables count மற்றும் values count normally equal-ஆக இருக்க வேண்ட……
ValueError: too many values to ……
ValueError: not enough values……
Tuple assignment-ன் மிக முக்கியமான use: Two variables values swap செய்வது. Supp……
Traditional method: temp = a a = b b = te……
Tuple assignment-ல் same datatype மட்டும் இருக்க வேண்டும் என்ற rule இல்லை. name, age, percentage……
Tuple assignment-க்கு parentheses compulsory இ……
Python tuple உருவாவதற்கு main……
பெயர் tuple assignment என்று commonly சொல்லப்பட்டாலும், unp……
Because iterable values seque……
String characters-யும் unpack செ……
Because "ABC" contains exactl……
a, b, c = range(3) print(a, b……
produces: 0, 1, 2…
Sometimes variables count and values count equal இருக்க வேண்டி……
a, *b = 10, 20, 30, 40…
Starred variable result list ……
a, b, *c = 10, 20, 30, 40, 50…
*a, b = 10, 20, 30, 40…
a, *b, c = 10, 20, 30, 40, 50…
Visualization: 10 20 30 40 50……
Sometimes ஒரு value தேவையில்லை. Conventionally……
Here age value 20 intentionally ignore செய்கிறோம். _ என்பது magic keyword இல்லை. இது ……
Tuple assignment functions-ல் மிகவும் useful. Function:……
Function multiple values return செய்வது போலத் தோன்றினாலும்: return……
Nested tuple-களையும் unpack செய்யலா……
Mapping: a ← 10 (b, c) ← (20,……
Tuple unpacking for loop-ல் மிக common. students = [ ("……
Each iteration: ("Arun", 80) ……
Dictionary .items() உடன் tuple unpacking மிகவும் important. ……
student.items() each time: ("name", "Raja") ("ma……
a, b = 10 Wrong. Because 10 is……
a, b = [10, 20, 30]…
ValueError: too many values t……
a, b, c = [10, 20]…
ValueError: not enough values……
a = 10, 20 does NOT assign a = 10 and something e……
Tuple assignment பற்றி நினைவில் வைத்திருக்க வேண்டிய முக்கிய points: Multiple variables can be assigned in one……
இந்த line மட்டும் நினைவில் வைத்த……
a, b, c = 10, 20, 30 Think: 1……
TRB / NET / SET / interview MCQ-ல் freque……
Reason: Right-hand side is evalua……
x = 10, 20 print(type(x)) Answer: R……
a, *b, c = 1, 2, 3, 4, 5…
Starred variable always colle……
Why does this work? a, b = b, a Answer: Python first evaluates the right-hand……
What is the output? a, b = 5,……
What is the output? a, b = 10……
What happens? a, b = 10, 20, ……
What is the output? x = 1, 2,……
What is the value of b? a, *b……
What is the output? a, b, c =……
Which symbol is mainly respon……
Predict the output: x, y, z = 100, 200, 300 print(y) Predict: a, b = 5, 7 a, b = b, a print……
Tuple Assignment என்பது Python-ல் multiple values-ஐ ……
Right side → Packing Left side → Unpacking Most important application: a, ……
One-line exam memory: Tuple Assignme……