**kwargs :-
Python में **kwargs का उपयोग किसी function में arbitrary number of keyword arguments प्राप्त करने के लिए किया जाता है। ये arguments function के अंदर एक dictionary के रूप में उपलब्ध होते हैं।
English Definition: **kwargs allows a function to accept any number of keyword arguments. These arguments are collected into a dictionary.
Syntax:
Example 1: Display Keyword Arguments
Output:
Explanation:
name, age और city keyword argument names हैं।
उनके corresponding values dictionary में store होती हैं।
kwargs एक dictionary है, जिसमें keys और values होती हैं।
Example 2: Display Student Details
Output:
Example 3: Access a Particular Value
Output:
Important: यदि dictionary में कोई key मौजूद नहीं है और उसे kwargs["key"] से access किया जाता है, तो KeyError आ सकता है। Optional key के लिए kwargs.get("key") इस्तेमाल कर सकते हैं।