Arbitrary keyword arguments
Arbitrary positional arguments are one way to add flexibility when creating custom functions, but you can also use arbitrary keyword arguments.
Your goal is to take the concat function that you created in the last exercise and modify it to accept arbitrary keyword arguments.
Bu egzersiz
Intermediate Python for Developers
kursunun bir parçasıdırEgzersiz talimatları
- Define
concat()as a function that accepts arbitrary keyword arguments calledkwargs. - Inside the function, loop over the keyword argument's values, using
kwargas the iterator. - Call
concat()with keyword arguments ofstartequal to"Python",middleequal to"is", andendequal to"great!".
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# 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!"))