python/using_kwargs.py

22 lines
599 B
Python

def create_user_profile(**kwargs):
if not kwargs:
return "No profile data provided."
profile_parts = []
for key, value in kwargs.items():
profile_parts.append(f"{key.capitalize()}: {value}")
# If you want to return a single string with all profile parts joined by newlines
return "\n".join(profile_parts)
# If you want to return a list of profile parts, use
# return profile_parts
# Example usage
profile = create_user_profile(name="Alice", age=30, occupation="Engineer")
print(profile)
profile_empty = create_user_profile()
print(profile_empty)