TUPLES AS RETURN VALUES
Python function-ல் ஒரே ஒரு value மட்டும் return செய்ய வேண்டும் என்ற rule இல்லை. ஒரு function: def student(): return "Arun", 85 இப்படி multiple values return செய்யலாம். இந்த: return "Arun", 85 Python-ல் conceptually: return ("Arun", 85) அதா…
Premium — locked
Advanced
23 min
193 cards
47 programs 7 MCQs v4
This is a premium lesson. You can see the shape of every card — unlock to read them.
Unlock
TUPLES AS RETURN VALUES - Pyt……
Premium
This card is part of the premium lesson.
Unlock
Python function-ல் ஒரே ஒரு value மட்டும் return செய்ய வேண்டும் என்ற rule இல்லை. ஒரு function: def student(): ……
Premium
This card is part of the premium lesson.
Unlock
Normal function: def add(): return 10 இது ஒரு value return செய்கிறது. 10 ஆனால்: def student(): return "Ravi",……
Premium
This card is part of the premium lesson.
Unlock
Basic flow
def get_values(): return 10, 20 Function call:……
Premium
This card is part of the premium lesson.
Unlock
Basic syntax
Call
or tuple unpacking: a, b = fu……
Premium
This card is part of the premium lesson.
Unlock
Program 1
def get_numbers(): get_numbers() என்ற function create செய்கிறோம். return 10, 20 இங்கு 10 and 20 return செய்கி……
Premium
This card is part of the premium lesson.
Unlock
Execution: get_numbers() called ↓ return 10, 20 ↓ Pyt……
Premium
This card is part of the premium lesson.
Unlock
Check type
def get_data(): return 100, 2……
Premium
This card is part of the premium lesson.
Unlock
This proves function returns ……
Premium
This card is part of the premium lesson.
Unlock
Tuple packing in return
Consider: return 10, 20, 30 Right side contains comma-separated values. Pytho……
Premium
This card is part of the premium lesson.
Unlock
Parentheses optional
Both are valid: def test(): return 10……
Premium
This card is part of the premium lesson.
Unlock
Tuple உருவாக parentheses முக்……
Premium
This card is part of the premium lesson.
Unlock
Return value unpacking
Function tuple return செய்தால்……
Premium
This card is part of the premium lesson.
Unlock
Example
Premium
This card is part of the premium lesson.
Unlock
How unpacking works
Function: def get_data(): return "Raja", 80 Returns: ("Raja", 80) Then: name……
Premium
This card is part of the premium lesson.
Unlock
Packing and unpacking
இந்த concept மிகவும் important. Function side: return "Raja", 80 Here: PACKING Caller side: name, mark = get_……
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
Return directly to variables
Same function: def student(): name = "Kumar" age = 20 mark……
Premium
This card is part of the premium lesson.
Unlock
Line by line explanation
def student(): Function definition. name = "Kumar" Local variable name. age = 20 Local variable age. mark = 9……
Premium
This card is part of the premium lesson.
Unlock
Why use tuple return values
Suppose ஒரு function இரண்டு r……
Premium
This card is part of the premium lesson.
Unlock
Comparison
difference
இரண்டும் தேவை. Instead of creating two separate functions: def add(a, b): return a + b def subtract(a, b): ……
Premium
This card is part of the premium lesson.
Unlock
Program 3 calculation
return addition, subtraction ……
Premium
This card is part of the premium lesson.
Unlock
Dry Run
Dry run calculation
Function call: calculate(30, 10) Parameters: a = 30 b = 10 Calculation: addition = 30 + 10……
Premium
This card is part of the premium lesson.
Unlock
Multiple calculations
A function can return many calculated results. def operations(a, b): return a + b, ……
Premium
This card is part of the premium lesson.
Unlock
Return quotient and remainder
Very common example: Division செய்யும்போது: Quotient Remainder இரண்டும் return செய்ய……
Premium
This card is part of the premium lesson.
Unlock
17 // 5 = 3 17 % 5 = 2 Return……
Premium
This card is part of the premium lesson.
Unlock
Built in example divmod
Python-ல் இதே concept use செய……
Premium
This card is part of the premium lesson.
Unlock
Example
Check
Divmod unpacking
q, r = divmod(17, 5) print(q)……
Premium
This card is part of the premium lesson.
Unlock
Here
Example
small, large = find_values([1……
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
Average and total
def marks(m1, m2, m3): total = m1 + m2 + m3 average = t……
Premium
This card is part of the premium lesson.
Unlock
Real time example
Student result function: def result(m1, m2, m3): total = m1 + m2 + m3 average = total / 3 if average >=……
Premium
This card is part of the premium lesson.
Unlock
One function returns: Total A……
Premium
This card is part of the premium lesson.
Unlock
Returning different data types
Tuple return values எல்லாம் same datatype இருக்க வேண்டிய அவசியம் இல்லை. d……
Premium
This card is part of the premium lesson.
Unlock
name, age, mark, passed = stu……
Premium
This card is part of the premium lesson.
Unlock
Return value as single variable
Function return tuple-ஐ unpac……
Premium
This card is part of the premium lesson.
Unlock
Example
Now tuple indexing பயன்படுத்தலாம்
Two ways to receive
Function: def get_data(): return 1……
Premium
This card is part of the premium lesson.
Unlock
Result
Access
Result
Premium
This card is part of the premium lesson.
Unlock
Comparison
Entire Tuple result = get_dat……
Premium
This card is part of the premium lesson.
Unlock
Result
Access through indexing: resu……
Premium
This card is part of the premium lesson.
Unlock
Result
Access directly using variabl……
Premium
This card is part of the premium lesson.
Unlock
Important count rule
Returned values count and receiving variables count normally equal ……
Premium
This card is part of the premium lesson.
Unlock
Common error 1
def test(): return 10, 20, 30 a, b = test(……
Premium
This card is part of the premium lesson.
Unlock
Error
ValueError: too many values t……
Premium
This card is part of the premium lesson.
Unlock
Common error 2
def test(): return 10, 20 a, ……
Premium
This card is part of the premium lesson.
Unlock
Error
ValueError: not enough values……
Premium
This card is part of the premium lesson.
Unlock
Star unpacking
Function நிறைய values return செய்தால் starred unpacking u……
Premium
This card is part of the premium lesson.
Unlock
*b remaining values-ஐ list-ஆக……
Premium
This card is part of the premium lesson.
Unlock
Star in middle
def numbers(): return 10, 20, 30, ……
Premium
This card is part of the premium lesson.
Unlock
Flow: Returned: (10, 20, 30, ……
Premium
This card is part of the premium lesson.
Unlock
Ignore return value
Function சில values return செய்……
Premium
This card is part of the premium lesson.
Unlock
Example
name, _, mark = student()…
Premium
This card is part of the premium lesson.
Unlock
Here: 20 தேவையில்லை. Conventi……
Premium
This card is part of the premium lesson.
Unlock
Returning nested tuple
Function nested tuple return செய்யலாம். d……
Premium
This card is part of the premium lesson.
Unlock
Nested unpacking: name, (m1, ……
Premium
This card is part of the premium lesson.
Unlock
Return statement stops function
Important return concept: Once return executed, func……
Premium
This card is part of the premium lesson.
Unlock
print("Hello") execute ஆகாது.……
Premium
This card is part of the premium lesson.
Unlock
Return without value
If: def test(): return Then r……
Premium
This card is part of the premium lesson.
Unlock
Example
This is different from return……
Premium
This card is part of the premium lesson.
Unlock
Empty tuple return
This: def test(): return () returns: () which is……
Premium
This card is part of the premium lesson.
Unlock
Single item tuple return
Very important exam concept. Suppose: d……
Premium
This card is part of the premium lesson.
Unlock
Because: (10) is only grouped ……
Premium
This card is part of the premium lesson.
Unlock
Now
return (10) returns: 10 Type: int But: retu……
Premium
This card is part of the premium lesson.
Unlock
Comparison
Function return vs print
Students commonly confuse ret……
Premium
This card is part of the premium lesson.
Unlock
Example
This displays values, but doe……
Premium
This card is part of the premium lesson.
Unlock
x becomes: None Correct retur……
Premium
This card is part of the premium lesson.
Unlock
Now
Premium
This card is part of the premium lesson.
Unlock
Comparison
Return vs print comparison
Example
does not return tuple. But:…
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
Function composition use
Tuple returns can be passed t……
Premium
This card is part of the premium lesson.
Unlock
Example
Flow: get_numbers() ↓ (10, 20……
Premium
This card is part of the premium lesson.
Unlock
Better unpacking version
def get_numbers(): return 10, 20 def a……
Premium
This card is part of the premium lesson.
Unlock
Real world use cases
Tuples as return values மிகவும் useful when function needs to return related information. Examples: Student: ……
Premium
This card is part of the premium lesson.
Unlock
Advantages
Tuples as return values use செய்தால்: Multiple related values ஒரே function-ல் return செய்யலாம். Multiple sepa……
Premium
This card is part of the premium lesson.
Unlock
Comparison
Comparison with list
Function tuple return: def te……
Premium
This card is part of the premium lesson.
Unlock
Result
Tuple is immutable. Function ……
Premium
This card is part of the premium lesson.
Unlock
Result
Premium
This card is part of the premium lesson.
Unlock
Comparison
Difference
return a, b means: return (a, b) not: return two independent objects s……
Premium
This card is part of the premium lesson.
Unlock
Function says: return a, b, c Python does: PACK → (a, b, c) Calle……
Premium
This card is part of the premium lesson.
Unlock
Question
def fun(): return 10, 20 x = fun() print(type(x)) ……
Premium
This card is part of the premium lesson.
Unlock
Trb point 2
def fun(): return 1, 2, 3 a, ……
Premium
This card is part of the premium lesson.
Unlock
Trb point 3
def fun(): return (10) print(type(fun())) An……
Premium
This card is part of the premium lesson.
Unlock
Trb point 4
What is returned by: def fun(……
Premium
This card is part of the premium lesson.
Unlock
Trb point 5
def fun(): return 1, 2 a, b, ……
Premium
This card is part of the premium lesson.
Unlock
Result
Reason: 2 returned elements b……
Premium
This card is part of the premium lesson.
Unlock
Question
Does Python really return multiple values from a function? Best answer: Technically, Python function returns ……
Premium
This card is part of the premium lesson.
Unlock
Interview point 2
What is the difference between: result = fun() and: a, b = fun()……
Premium
This card is part of the premium lesson.
Unlock
Wrong assumption: return a, b means two separate retur……
Premium
This card is part of the premium lesson.
Unlock
What is the output? def fun()……
Premium
This card is part of the premium lesson.
Unlock
What is the type? def fun(): ……
Premium
This card is part of the premium lesson.
Unlock
What is the output? def fun()……
Premium
This card is part of the premium lesson.
Unlock
What happens? def fun(): retu……
Premium
This card is part of the premium lesson.
Unlock
What is the output? def fun()……
Premium
This card is part of the premium lesson.
Unlock
Mcq 6
Which creates a one-element tuple? A) return (……
Premium
This card is part of the premium lesson.
Unlock
What is the value of b? def f……
Premium
This card is part of the premium lesson.
Unlock
What does this function retur……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 1
Predict: def get(): return 10……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 2
Predict: def get(): return "A……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 3
Predict: def calculate(x, y): return ……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 4
Predict: def test(): return 1, 2,……
Premium
This card is part of the premium lesson.
Unlock
Tuples as Return Values என்பது Python f……
Premium
This card is part of the premium lesson.
Unlock
Example
Actually returns: ("Ravi", 90……
Premium
This card is part of the premium lesson.
Unlock
or unpack: name, mark = stude……
Premium
This card is part of the premium lesson.
Unlock
Most important exam statement: Python function appears t……
Premium
This card is part of the premium lesson.
Unlock