Arbitrary keyword arguments
Arbitrary positional arguments कस्टम फंक्शन बनाते समय flexibility जोड़ने का एक तरीका हैं, लेकिन आप arbitrary keyword arguments भी इस्तेमाल कर सकते हैं.
आपका लक्ष्य पिछले अभ्यास में बनाए गए concat फंक्शन को लेकर उसे ऐसा संशोधित करना है कि वह arbitrary keyword arguments स्वीकार करे.
यह अभ्यास पाठ्यक्रम का हिस्सा है
इंटरमीडिएट Python फॉर डेवलपर्स
अभ्यास निर्देश
concat()को एक ऐसे फंक्शन के रूप में परिभाषित करें जोkwargsनाम के arbitrary keyword arguments स्वीकार करे.- फंक्शन के अंदर, keyword arguments के values पर
kwargको iterator के रूप में इस्तेमाल करते हुए लूप चलाएँ. concat()को ऐसे keyword arguments के साथ कॉल करें जिनमेंstartबराबर"Python",middleबराबर"is", औरendबराबर"great!"हों.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Define a function called concat
def ____(____):
"""Concatenates keyword arguments into a single string with spaces."""
result = ""
# Iterate over the Python kwargs
for ____ in kwargs.____():
result += " " + kwarg
return result
# Call the function
print(____(____="Python", ____="is", ____="great!"))