Home >> Python Tutorial >> Parameters and Arguments
Edit Template
Edit Template

Parameters and Arguments in Hindi

What is Parameters and Arguments in Function

किसी Function मे अगर हमे कोई value या data देना होता है तो हम Parameters और Arguments का use करते है।

What is Function Parameters

function को define करते समय function name मे parentheses के अंदर हम जो variable देते है उन्हे parameters कहा जाता है। Parameters को Formal Arguments भी कहा जाता है। 

SYNTEX

# Creating Function
def function_name(Parameter):
       # Function body

*args

अगर हम parameter मे variables के आगे “ * “ का use करे तो, अब ये parameter एक mutable object (list, set, tuple) को लेगा। but आम-तौर पर हम किसी variable के आगे ” * ” नहीं लगाते बल्कि ” *args  ” नाम का parameter create करते है। 

**kwargs

अगर हम parameter मे variables के आगे “ ** “ का use करे तो, अब ये parameter एक dictionary को लेगा। but आम-तौर पर हम किसी variable के आगे ” ** ” नहीं लगाते बल्कि ” **kwargs  ” नाम का parameter create करते है। 

What is Function Arguments

function को call करते समय function name मे parentheses के अंदर हम जो भी value देते है उन्हे arguments कहा जाता है। हम जिस function मे arguments देंगे वो उस function के parameters मे assign हो जाएगा। Arguments को Actual Arguments भी कहा जाता है। 

SYNTEX

# Calling Function
print(function_name(Arguments))
🐍
Example 1.py
Copy to clipboard
# Function with Parameters & Arguments
def demo1(a, b):
    print(a, b)

demo1(1, "jay")
# Output: 1 jay

# Function with *args, **kwargs
def func(*args, **kwargs):
    print("Positional:", args)
    print("Keyword:", kwargs)

func(10, 20, 30, x=5, y=15)

'''Output:
Positional: (10, 20, 30)
Keyword: {'x': 5, 'y': 15}
'''

Types of Arguments

Positional Arguments

अगर हम किसी function को call करते समय arguments को order (position) के basis पर pass करते है तो इसे position arguments कहते है।

Positional argument में order matter करता है मतलब अगर हम function calling के समय “24” & “jay” arguments pass करते है तो “24” first number पर है तो ये function के first parameter में जाएगा इसी तरह “jay” second parameter में जाएगा, आम-तौर पर हम इसी type से arguments को pass करते है।

🐍
Example 2.py
Copy to clipboard
def student_info(name, age):
    print(f"Name: {name}, Age: {age}")

student_info("jay", 24)

Keyword Arguments

अगर हम किसी function को call करते समय arguments को parameter के name के साथ pass करते है तो इसे Keyword Argument कहते है।

Keyword argument में order matter नहीं है for example किसी function में “student” नाम का parameter पहले है और “age” नाम का parameter दूसरे number पर है, और हमने function calling के समय पहले “age” parameter को initialize करके pass किया फिर “student” को तो भी “student” में student का name जाएगा और “age” में उसका age जाएगा।

🐍
Example 3.py
Copy to clipboard
def student_info(student, age):
    print(f"Name: {student}, Age: {age}")

student_info(age=22, student="jay")

Default Arguments

अगर हम function parameter मे ही value को assign कर दे तो इसे default parameter value या default agruments कहा जाएगा। अब हम function को call करते समय arguments न दे तो भी हमारा function work करेगा , but अगर हमने argument दे दिया तो ये default parameter value को overwrite कर देगा 

🐍
Example 4.py
Copy to clipboard
def student_info(student = "jay", age = 25):
    print(f"Name: {student}, Age: {age}")

student_info()

Mutable Default Arguments

अगर हम किसी function के parameter का default value में एक mutable object (list, set, dictionary, etc.) को देते है तो इसे mutable default argument कहते है।

But इसमे एक दिक्कत होता है, जैसे हमने किसी empty list को default argument में दिया तो program में जब ये function execute होगा तो ये empty list create हो जाएगा और अगर इस list में कोई item append होता है तो ये item हमेशा के लिए इस list में आ जाएगा, अगर हम चाहते है की उस function में हमे वो empty list मिले तो ये possible नहीं है इसलिए इस list में directly किसी item को add करने के बजाय हमे condition को use करना चाहिए।

🐍
Example 5.py
Copy to clipboard
def add_item(item, basket=[]):
    basket.append(item)
    return basket

print(add_item("Apple"))    
# output: ['Apple']
print(add_item("Banana"))   
# output: ['Apple', 'Banana']

Function as Parameters and Arguments

Python में function भी एक object होता है, इसीलिए हम किसी function को किसी दूसरे function के parameter में argument के रूप में pass कर सकते है।

🐍
Example 6.py
Copy to clipboard
def square(x):
    return x*x

def apply_func(func, value):
    return func(value)

print(apply_func(square, 5))   
# Output: 25

उम्मीद करते है कि आपको function मे parameters और arguments क्या होता है ये अच्छे समझ मे आ गया होगा। अपने learning को continue रखने के लिए next button पर click करे,

Add a comment...

  • All Posts
  • Artificial Intelligence
  • Computer Fundamentals
  • Computer Networks
  • Data Analytics
  • Data Science
  • DBMS
  • Deep Learning
  • Digital Fundamentals
  • DSA with Python
  • Excel
  • Exercise
  • Git & Github
  • Machine Learning
  • Matplotlib
  • Natural Language Processing
  • NumPy
  • Operating System
  • Pandas-s
  • Power BI
  • Python Tutorial
  • Scikit-learn
  • Seaborn
  • SQL & MySQL
Dunder Methods

Table of Contents All Chapters 1. Dunder Methods 2. Commonly Used Dunder Methods   Python Tutorial Python Introduction Identation &...

Encapsulation

Table of Contents All Chapters 1. Encapsulation 2. Access Modifiers      2.1. Public Members      2.2. Protected Members...

Lambda Function

Table of Contents All Chapters 1. Lambda Function 2. Nestesd Lambda Function 3. Lambda Function with if-else 4. Lanbda with...

Nested Function

Table of Contents All Chapters 1. Nested Function 2. Return Function from Function 3. Higher Order Function 4. Function Recursion...

Context Manager

Table of Contents All Chapters 1. Context Manager 2. with Statement      2.1. __enter__() Method      2.2. __exit__()...

File Pointer

Table of Contents All Chapters 1. File Pointer 2. File Pointer Methods      2.1. tell() Method      2.2....

File Handling

Table of Contents All Chapters 1. File Handling 2. Types of File 3. open() and close() Methods 4. File Modes...

Edit Template
Scroll to Top