Keyword Arguments in Python :-
Python में Keyword Arguments वे arguments होते हैं जिन्हें function call करते समय parameter के नाम के साथ value देकर pass किया जाता है। इसमें argument की value, parameter के नाम से identify होती है।
in English
Keyword arguments are arguments passed to a function by explicitly specifying the parameter names along with their values during the function call.
Example
Output:
Explanation:
name="Rahul" एक keyword argument है।
age=20 भी एक keyword argument है।
Parameter names (name और age) के माध्यम से values pass की गई हैं।
Using Keyword Arguments
Function call करते समय parameter का नाम लिखकर और उसके बाद = operator की सहायता से value देना Using Keyword Arguments कहलाता है।
in English
Using keyword arguments means passing values to a function by specifying the parameter names in the function call.
Syntax function_name(parameter1=value1, parameter2=value2) Example 1: Using Keyword Arguments
Output:
Example 2: Changing the Order of Arguments
Output:
Explanation:
इस example में arguments का order function definition से अलग है। फिर भी सही output मिलता है क्योंकि प्रत्येक value उसके parameter name से जुड़ी है।
Example 3: Using Keyword Arguments with Default Values
Output:
Explanation:
name="Rahul" से name की value दी गई।
course="O Level" से course की default value बदल गई।
city के लिए कोई value नहीं दी गई, इसलिए उसकी default value "Azamgarh" उपयोग हुई।
Important Rule: Positional arguments को keyword arguments से पहले रखना चाहिए।
Incorrect Example:
Output:
SyntaxError: positional argument follows keyword argument
Correct Example:
Output:
Output:
Rahul 20
Positional vs Keyword Arguments :-
Example: Positional Arguments
Output:
Example: Keyword Arguments
Output: