Practice Variable-Length Arguments: *args and **kwargs - 6.6 | Functions in Python | Python Programming Language
Students

Academic Programs

AI-powered learning for grades 8-12, aligned with major curricula

Professional

Professional Courses

Industry-relevant training in Business, Technology, and Design

Games

Interactive Games

Fun games to boost memory, math, typing, and English skills

Variable-Length Arguments: *args and **kwargs

6.6 - Variable-Length Arguments: *args and **kwargs

Enroll to start learning

You’ve not yet enrolled in this course. Please enroll for free to listen to audio lessons, classroom podcasts and take practice test.

Learning

Practice Questions

Test your understanding with targeted questions

Question 1 Easy

What does *args allow in a Python function?

💡 Hint: Think about how many numbers you can add to a function.

Question 2 Easy

What type of data structure does **kwargs use?

💡 Hint: Consider how you can access values by keys.

4 more questions available

Interactive Quizzes

Quick quizzes to reinforce your learning

Question 1

What does the * in *args signify?

Terminates the arguments
Collects extra positional arguments
Collects keyword arguments

💡 Hint: Think about what happens to extra inputs in a function.

Question 2

True or False: **kwargs must always include at least one argument.

True
False

💡 Hint: Remind yourself of the flexibility provided by kwargs.

2 more questions available

Challenge Problems

Push your limits with advanced challenges

Challenge 1 Hard

Design a function that accepts an unknown number of scores, calculates the average, and allows for an optional keyword argument to specify whether to round the result.

💡 Hint: Think about how you can control the output format with a keyword argument.

Challenge 2 Hard

Write a function with both args and *kwargs that returns a formatted string detailing provided items and attributes.

💡 Hint: Make use of both collected positional and keyword arguments to build your output.

Get performance evaluation

Reference links

Supplementary resources to enhance your learning experience.