Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Write a function that handles keyword arguments

Use **kwargs to accept arbitrary keyword arguments and process them.

Python practice8 minFunctions & ScopeBeginnerLast updated March 17, 2026

Problem statement

Implement count_kwargs(**kwargs) which accepts any number of keyword arguments and returns an integer count of those keyword arguments. The function should work when called with zero or many keyword arguments.

Task

Create a function count_kwargs(**kwargs) that returns how many keyword arguments were passed.

Examples

Count two keyword args

Input

count_kwargs(name='Alice', active=True)

Output

2

Two keyword arguments (name and active) were provided.

Input format

Zero or more keyword arguments in the form key=value.

Output format

An integer representing the number of keyword arguments passed.

Constraints

Do not use external libraries. The order of kwargs is not important; only the count matters.

Samples

Sample 1

Input

count_kwargs()

Output

0

No keyword arguments, so the count is 0.