Print Keyword Arguments

Write a Python function named print_kwargs that accepts an arbitrary number of keyword arguments. The function should print out the keys and values in the format ‘key: value’.

Example 1:

Input: print_kwargs(name='John', age=25) 
Output: 'name: John' 'age: 25'

Example 2:

Input: print_kwargs(city='New York', temperature=75, weather='Sunny') 
Output: 'city: New York' 'temperature: 75' 'weather: Sunny'

You can use a for loop to iterate over the keyword arguments.

def print_kwargs(**kwargs):
    for key, value in kwargs.items():
        print(f'{key}: {value}')

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!