Parameter A parameter is a variable written in the function… TRB CSI › Python Programming › Return values, Parameters,

Parameter A parameter is a variable written in the function…

Parameter A parameter is a variable written in the function definition to receive a value from the function call. தமிழில்: Function call-லிருந்து வரும் value-ஐ receive செய்ய function definition-ல் எழுதப்படும் variable தான் Parameter.

Free Beginner 21 min 209 cards 35 programs 9 MCQs v3

Return Values and Parameters in Python

Python function-ஐ சரியாக புரிந்து கொள்ள இரண்டு words ரொம்ப முக்கியம்:

Algorithm
  1. Parameter
  2. Return Value
  1. Parameters
  2. Function Processing
  3. Return Value
  4. Output / Result
Program
Example
Python 2 lines
1def add(a, b):
2    return a + b
Program
Python 2 lines
1result = add(10, 20)
2print(result)
Explanation
இங்கே
  • a, b → Parameters
  • 10, 20 → Arguments
  • a + b → Processing
  • return 30 → Return Value
Definition
Meaning

Parameter

A parameter is a variable written in the function definition to receive a value from the function call.

Function call-லிருந்து வரும் value-ஐ receive செய்ய function definition-ல் எழுதப்படும் variable தான் Parameter.

Program
Example
Python 2 lines
1def add(a, b):
2    return a + b
Verified output
30
Learning Run Mode — this is the output the author verified, not a live execution.
Explanation
Core idea

இரண்டும் parameters.

இங்கே

a
b

Simple Explanation
Suppose ஒரு box இருக்கு

Number 1 → [ ]

Number 2 → [ ]

இந்த empty places தான் parameters.

Function

def add(a, b)

இங்கே

a = first value வாங்கும் இடம்

b = second value வாங்கும் இடம்

Call

add(10, 20)

Now

a = 10

b = 20

Flow

Function Definition

def add(a, b):
        ↑  ↑
   Parameters

Call:

add(10, 20)
↑ ↑
Arguments

Mapping
a10
b20
Then
  1. a + b
  2. 10 + 20
  3. 30
Comparison
Parameter vs argument
Context

இது மிகவும் முக்கியமான exam concept.

return a + b
add(10, 20)

a, b = Parameters

add(10, 20)

10, 20 = Arguments

Memory Trick
Context
  • Parameter → Definition
  • Argument → Call
P = Placeholder
A = Actual value

Parameter = Placeholder
Argument  = Actual value
Explanation
Why parameters
Core idea

add()

Parameters இல்லாமல்
def add():
    a = 10
    b = 20
    print(a + b)
Output
30

ஆனால் மீண்டும் 50 + 60 calculate செய்ய வேண்டுமென்றால் function-க்குள் values change செய்ய வேண்டும்.

Parameters பயன்படுத்தினால்:

Program
Python 2 lines
1def add(a, b):
2    print(a + b)
Verified output
add(10, 20)
add(50, 60)
add(100, 200)
Learning Run Mode — this is the output the author verified, not a live execution.
Output
add(10, 20)
add(50, 60)
add(100, 200)
Output
30
110
300

ஒரே function different values-க்கு வேலை செய்கிறது.

இதுதான்:

Reusability

Program
Python 2 lines
1def multiply(x, y):
2    print(x * y)
Verified output
20
Learning Run Mode — this is the output the author verified, not a live execution.
Explanation
Core idea

multiply(5, 4)

Output
20
Explanation
Core idea

multiply(5, 4)

def multiply(x, y)

x and y parameters.

Detail 02

Function call.

Here
5
x
4
y
Then
  1. x * y
  2. 5 * 4
  3. 20
Explanation
Multiple parameters
Core idea

Function ஒரு parameter மட்டும் அல்ல.

Detail 01

Multiple parameters வைத்துக்கொள்ளலாம்.

Detail 02
def student(name, age, mark):
    print(name)
    print(age)
    print(mark)
Detail 03

student("Ravi", 20, 85)

Mapping
name = "Ravi"
age  = 20
mark = 85
Explanation
No parameter function

Parameter இல்லாமலும் function உருவாக்கலாம்.

def greet()

print("Hello")

greet()

இங்கே

Parameters = 0

Arguments = 0

Explanation
Parameter count

இந்த function

def add(a, b)

print(a + b)

normally two arguments expect செய்கிறது.

Correct

add(10, 20)

Wrong

add(10)

Because one required argument missing.

Common Mistake
print(a + b)

add(10)

Missing required positional argument

a = 10
b = ?
b-க்கு value இல்லை.
Explanation
Positional parameters and arguments
Core idea

Normal arguments order அடிப்படையில் parameter-க்கு assign ஆகும்.

Detail 01
def student(name, age):
    print(name)
    print(age)
Detail 02

student("Ravi", 20)

Mapping
First argument
first parameter
Second argument
second parameter
So
name = Ravi
age = 20
Detail 05

இதனை Positional Arguments என்கிறோம்.

Program
Example
Python 2 lines
1def subtract(a, b):
2    print(a - b)
Verified output
5
Learning Run Mode — this is the output the author verified, not a live execution.
Explanation
Core idea

subtract(10, 5)

Output
5

But:

subtract(5, 10)

Output
-5

ஏன்?

Position change ஆகிவிட்டது.

Explanation
Keyword arguments
Core idea

Parameter name சொல்லி value கொடுக்கலாம்.

Detail 01
def student(name, age):
    print(name)
    print(age)
Detail 02

student(age=20, name="Ravi")

Output
Ravi
20

இங்கே order change ஆனாலும் problem இல்லை.

Because parameter names explicitly given.

Explanation
Default parameter
Core idea

Parameter-க்கு default value கொடுக்கலாம்.

def greet(name="Student")

print("Hello", name)

Detail 02

greet()

Output
Hello Student

Call with argument:

greet("Ravi")

Output
Hello Ravi
Concept

name = default parameter value

Student

use ஆகும்.

Passed value

use ஆகும்.

Explanation
Default parameter rule
Core idea

Required parameter first.

Detail 01

Default parameter after it.

Correct
def student(name, age=18):
    print(name, age)
Avoid

def student(name="Ravi", age):

Reason

non-default parameter cannot normally follow a default parameter in this form.

Explanation
Variable length parameter
Core idea

use செய்யலாம்.

எத்தனை values வரும் என்று தெரியவில்லை என்றால்

*args

Program
Example
Python 2 lines
1def numbers(*x):
2    print(x)
Verified output
(10, 20, 30, 40)
Learning Run Mode — this is the output the author verified, not a live execution.
Explanation
Core idea

numbers(10, 20, 30, 40)

Output
(10, 20, 30, 40)
Important
  1. *args values generally

    Tuple

  2. ஆக collect ஆகும்.

Program
Example
Python 2 lines
1def total(*numbers):
2    print(sum(numbers))
Verified output
60
Learning Run Mode — this is the output the author verified, not a live execution.
Explanation
Core idea

total(10, 20, 30)

Output
60
Explanation
Keyword variable parameter
Core idea

**kwargs

Detail 01

multiple keyword values collect செய்யும்.

def student(**data)

print(data)

Detail 03

student(name="Ravi", age=20, mark=90)

Output
{'name': 'Ravi', 'age': 20, 'mark': 90}
Important
  1. *args → Tuple

  2. **kwargs → Dictionary

  3. Memory:

Important

- → many positional values

Important

** → many keyword values

Explanation
Return value
இப்போது second major concept

Return Value

A return value is the result sent back by a function to the place where the function was called.

தமிழில்

Function தனது processing முடிந்த பிறகு result-ஐ function call நடந்த இடத்துக்கு திருப்பி அனுப்புவது Return Value.

Simple Explanation
Core idea

இந்த 30 தான் return value.

Function machine
  1. 10, 20
  2. add()
  3. 10 + 20
  4. 30
Syntax
Python 2 lines
1def function_name(parameters):
2    return value
Program
Example
Python 2 lines
1def add(a, b):
2    return a + b
Program
Python 2 lines
1def add(a, b):
2    return a + b
Program
Python 1 lines
1result = add(10, 20)
Program
Python 1 lines
1print(result)
Verified output
30
Learning Run Mode — this is the output the author verified, not a live execution.
Output
30
Flow
  1. add(10, 20)
  2. a = 10b = 20
  3. a + b
  4. 30
  5. return 30
  6. result = 30
Explanation
Return meaning
Core idea

அதாவது return screen-ல் print செய்யாது.

இந்த line

return a + b

என்பது
  1. Calculate a + b
  2. Send that result back
Detail 03

Value-ஐ caller-க்கு back அனுப்பும்.

Comparison
Print vs return
Core idea

இது மிக முக்கியமான concept.
print()
def add(a, b):
print(a + b)
add(10, 20)

Output
30

Screen-ல் result காட்டுகிறது.

Program
Python 3 lines
1return
2def add(a, b):
3    return a + b
Program
Python 2 lines
1x = add(10, 20)
2print(x)
Verified output
30
Learning Run Mode — this is the output the author verified, not a live execution.
Output
30

இங்கே 30 முதலில் x-க்கு வருகிறது.

Table
Main difference
print()return
Screen-ல் காட்டும்Caller-க்கு value அனுப்பும்
Display purposeFunction result purpose
Value reuse difficultReturned value reuse செய்யலாம்
Function continue ஆகலாம்return function-ஐ end செய்கிறது
Concept
Concept example
Context

Using print

print(x * x)

a = square(5)

print(a)
Output
25
None

Why None?

Because function explicit return value கொடுக்கவில்லை.

Program
Python 3 lines
1Using return
2def square(x):
3    return x * x
Program
Python 1 lines
1a = square(5)
Program
Python 1 lines
1print(a)
Verified output
25
Learning Run Mode — this is the output the author verified, not a live execution.
Output
25
Program
Now
Python 1 lines
1a = 25
Important
Very important
  1. Function-ல் explicit return இல்லையென்றால் Python automatically

    None

  2. return செய்யும்.

Program
Example
Python 2 lines
1def test():
2    print("Hello")
Program
Python 1 lines
1x = test()
Program
Python 1 lines
1print(x)
Verified output
Hello
None
Learning Run Mode — this is the output the author verified, not a live execution.
Output
Hello
None
Explanation
Return can be stored
def add(a, b)

return a + b

result = add(5, 10)

Now

result = 15

Returned value variable-ல் store செய்யலாம்.

Explanation
Return can be reused
Core idea

print(result * 2)

def add(a, b)

return a + b

Result

= add(10, 20)

Output
60
Program
Because
Python 2 lines
1result = 30
230 × 2 = 60
Verified output
30
Learning Run Mode — this is the output the author verified, not a live execution.
Explanation
Return can be directly printed
Core idea

Variable compulsory இல்லை.

def add(a, b)

return a + b

Detail 02

print(add(10, 20))

Output
30
Explanation
Return in expression
Core idea

Returned function value another calculation-க்குள் பயன்படுத்தலாம்.

def square(x)

return x * x

Result

= square(5) + 10

Detail 03

print(result)

Output
35
  1. square(5)
  2. 25

25 + 10 = 35

Explanation
Return stops function
Core idea

return execute ஆனதும் function execution immediately ends.

Detail 01
def test():
    print("A")
    return
    print("B")
Detail 02

test()

Output
A

B execute ஆகாது.

Flow
  1. print("A")
  2. return
  3. Function End

Anything after return in that execution path will not run.

Explanation
Return with value
def test()

return 100

Call

x = test()

Now

x = 100

Explanation
Return without value

Python

def test()

return

This returns

None

Program
Example
Python 2 lines
1def test():
2    return
Program
Python 1 lines
1print(test())
Verified output
None
Learning Run Mode — this is the output the author verified, not a live execution.
Output
None
Explanation
Multiple return values
Core idea

Python function multiple values return செய்யலாம்.

def calculate(a, b)

return a + b, a - b

Detail 02

x, y = calculate(10, 5)

Detail 03
print(x)
print(y)
Output
15
5
Explanation
How it works
This

return a + b, a - b

produces conceptually

(15, 5)

Python அதை tuple ஆக return செய்கிறது.

Explanation
Check return type
Core idea
print(result)
print(type(result))
def calculate(a, b)

return a + b, a - b

Result

= calculate(10, 5)

Output concept

(15, 5)
<class 'tuple'>

Explanation
Unpacking return value
Core idea

x, y = calculate(10, 5)

means
x = 15
y = 5
Detail 02

This is tuple unpacking.

Explanation
Return with condition

def check_number(x)

if x > 0

return "Positive"

else

return "Negative"

print(check_number(10))

Output
Positive
Explanation
Early return
Core idea

Sometimes function-ஐ early stop செய்ய return பயன்படுத்தலாம்.

Detail 01
def check_age(age):
    if age < 18:
        return "Not Eligible"
Detail 02

return "Eligible"

Detail 03

print(check_age(15))

Output
Not Eligible

First return execute ஆனதும் function ends.

Explanation
Parameter and return together
ஒரு good reusable function usually
Parameter
Input
Return
Output
Program
Example
Python 2 lines
1def cube(number):
2    return number ** 3
Input
number = 4

64

Program
Python 1 lines
1answer = cube(4)
Program
Now
Python 1 lines
1answer = 64
Verified output
25
Learning Run Mode — this is the output the author verified, not a live execution.
Real Life Example
Real time example

return "Pass"

return "Fail"

status = result(75)

print(status)
  1. 75
  2. mark parameter
  3. 75 >= 40
  4. True
  5. return "Pass"
  6. status = "Pass"
Explanation
Parameter types
Core idea

Exam point-ஆக commonly parameters / arguments குறித்து கேட்கப்படும் forms:

Explanation
Core idea
  • 1. Positional
  • 2. Keyword
  • 3. Default
  • 4. Variable-length (*args)
  • 5. Keyword variable-length (**kwargs)
Explanation
Positional
Core idea

add(10, 20)
10 → a
20 → b

def add(a, b)

return a + b

Detail 02

Position decides mapping.

Explanation
Keyword
Core idea

student(age=20, name="Ravi")

def student(name, age)

print(name, age)

Detail 02

Parameter name decides mapping.

Explanation
Default
Core idea

print(power(5))

def power(x, p=2)

return x ** p

Output
25
Program
Because default
Python 1 lines
1p = 2
Program
But
Python 1 lines
1print(power(5, 3))
Verified output
125
Learning Run Mode — this is the output the author verified, not a live execution.
Output
125

Argument overrides default.

Explanation
Args
Core idea

print(total(10, 20, 30))

def total(*numbers)

return sum(numbers)

Output
60
Explanation
Kwargs
Core idea

print(display(name="Ravi", age=20))

def display(**details)

return details

Output
{'name': 'Ravi', 'age': 20}
Concept
Local parameter concept

Parameters normally function-ன் local variables போல behave செய்கின்றன.

Program
Example
Python 2 lines
1def show(x):
2    print(x)
Explanation
Core idea

show(10)

Detail 01

x function execution-க்குள் value receive செய்கிறது.

Detail 02

Function outside:

Program
Python 1 lines
1print(x)
Explanation
Core idea

என்றால் x separately defined இல்லையென்றால் error வரும்.

Concept
Pass by object reference concept

Python-ல் arguments pass செய்யும் behavior-ஐ simple-ஆக:

Function parameter object-ஐ reference செய்கிறது.

Program
Example
Python 2 lines
1def change(x):
2    x = 100
Program
Python 2 lines
1a = 10
2change(a)
Program
Python 1 lines
1print(a)
Verified output
10
Learning Run Mode — this is the output the author verified, not a live execution.
Output
10

Function-க்குள் x = 100 என்று reassign செய்ததால் outside a change ஆகவில்லை.

இந்த concept later mutable/immutable objects படிக்கும்போது மிகவும் முக்கியம்.

Important
  1. parameter value storage box என்று மட்டும் நினைக்காமல்

    Function caller மற்றும் function body-க்கு இடையிலான input connection

  2. என்று புரிந்துகொள்ளுங்கள்.

  3. Likewise

    return என்பது function body மற்றும் caller-க்கு இடையிலான output connection.

  4. So

    Caller

  5. ├── Argument

  6. Parameter

  7. Function

  8. Return

  9. Caller

Comparison
Parameter vs Return Value
ParameterReturn Value
Function-க்கு inputFunction-இலிருந்து output
Definition-ல் writtenreturn மூலம் sent
Argument receivesResult gives back
Function start sideFunction end/result side
Memory Trick
ARGUMENTPARAMETERFUNCTIONRETURN

Tamil memory:

Argument கொடுக்கிறோம் → Parameter வாங்குகிறது → Function வேலை செய்கிறது → Return result திருப்பிக் கொடுக்கிறது.

Common Mistake
Error 1
Context

Parameter and Argument same என்று நினைப்பது

Related concepts தான், ஆனால் exact same அல்ல.

a, b = parameters.
add(10, 20)
10,20 = arguments.
Common Mistake
Error 2
Context

print means return

Wrong understanding.

print(a + b)

This displays.

return a + b

This returns.

Common Mistake
Error 3
Context

Code after return will execute

return 10
    print("Hello")

print("Hello") execute ஆகாது.

Common Mistake
Error 4
Context

Too few arguments

return a + b

add(10)

b missing.

Common Mistake
Error 5
Context

Too many arguments

return a + b

add(10, 20, 30)

Function only two required positional parameters expects.

Common Mistake
Error 6
Context

Expecting return without storing or using it

return a + b

add(10, 20)

Function returns 30, but this script does not display it automatically.

print(add(10, 20))

x = add(10, 20)
print(x)
TRB Point

1. Parameter appears in?

TRB Point

Function definition

TRB Point

1. Argument appears in?

TRB Point

Function call

TRB Point

1. Which keyword sends result back?

TRB Point

return

TRB Point

1. Function without explicit return gives?

TRB Point

None

TRB Point

1. Does return terminate current function execution?

TRB Point

Yes

TRB Point

1. Multiple values returned by Python are commonly packed as?

TRB Point

Tuple

TRB Point

1. Default parameter means?

TRB Point

A parameter already has a predefined value.

TRB Point

1. *args generally stores?

TRB Point

Tuple

TRB Point

1. **kwargs generally stores?

TRB Point

Dictionary

TRB Point

1. print() and return same?

TRB Point

No

Interview Point

What is a parameter?

A parameter is a variable in the function definition that receives an argument when the function is called.

What is an argument?

An argument is the actual value supplied to a function during a function call.

What does return do?

return sends a result back to the caller and terminates the current function execution.

What happens if a function has no return statement?

Python implicitly returns:

None
Can a Python function return multiple values?

Yes.

Explanation
Example
Core idea

return a, b

Detail 01

They are normally packed into a tuple.

Detail 02

Can returned values be used in expressions?

Detail 03

Yes.

Program
Python 1 lines
1result = square(5) + 10
Verified output
A
None
Learning Run Mode — this is the output the author verified, not a live execution.
MCQ
181In the following code, x is: def square(x): return x * x
Choose one answer
MCQ
182In: square(5) 5 is:
Choose one answer
MCQ
183Which keyword returns a value?
Choose one answer
MCQ
184What does a function without explicit return return?
Choose one answer
MCQ
185What is output? def add(a, b): return a + b print(add(2, 3))
Choose one answer
Output
A
None

Answer: A followed by None

Algorithm
  1. Which one generally collects variable positional arguments?
MCQ
189
Choose one answer

Answer: B

Algorithm
  1. **kwargs generally produces:
MCQ
192
Choose one answer

Answer: C

Algorithm
  1. What happens after return executes?
MCQ
195
Choose one answer

Answer: B

Algorithm
  1. Which statement is correct?
MCQ
198
Choose one answer

Answer: C

Practice
Practice 1
def add(a, b):
    return a + b

print(add(15, 20))
Output
35
Practice
Practice 2

Identify parameters and arguments:

def multiply(x, y):
    return x * y

multiply(4, 5)

Answer:

Parameters
x, y
Arguments
4, 5
Return
20
Practice
Practice 3
def get_name():
    return "Python"

x = get_name()

print(x)
Output
Python
Practice
Practice 4
def calculate(a, b):
    return a + b, a * b

x, y = calculate(5, 3)

print(x)
print(y)
Output
8
15
Summary
  1. Function data flow
  2. Arguments
  3. Parameters
  4. Function Processing
  5. Return Value
  6. Caller
Remember
  1. Parameter → Function definition variable

  2. Argument → Actual value during call

  3. Return → Result sent back

  4. Most important example

  5. def add(a, b)

    return a + b

  6. result = add(10, 20)

  7. Here

    a, b → Parameters

  8. 10, 20 → Arguments

  9. 30 → Return Value

  10. result → Returned value stored here

Explanation
Short description
Core idea

Parameter என்பது function definition-ல் input value receive செய்யப்படும் variable. Argument என்பது function call செய்யும்போது கொடுக்கப்படும் actual value. return statement function உருவாக்கிய result-ஐ caller-க்கு திருப்பி அனுப்புகிறது. Function-ஐ ஒரு machine போல நினைத்தால்: Arguments are input, Parameters receive input, function processes it, and Return Value is the output.

Text size
17px
Theme
Contents
Print / PDF
Program