Skip to the content

**kwargs

Python · Unit 10: More on functions

With ** before a parameter, the function takes any number of keyword arguments, the name=value kind. They arrive together in a dictionary: each name is a key.

It's usually called **kwargs.

def card(**data):
    print(data)

card(name="Ana", age=15)

Prints

{'name': 'Ana', 'age': 15}

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Predict the output

    What does this code print?

  2. 2. Multiple choice

    Which call works?

  3. 3. Complete the code

    Fill in the blank so the function takes any grades you want, each one with its name.

  4. 4. Predict the output

    What does this code print?

  5. 5. Find the bug

    This program should print each piece of data on the card next to its name. Which line has the bug?

  6. 6. Complete the code

    Fill in the blank to give badge the data in the dictionary.

  7. 7. Predict the output

    What does this code print?

  8. 8. Find the bug

    This program should print 75, the price after the discount. Which line has the bug?

  9. 9. Put the lines in order

    Put the function in order. It adds up the prices it gets, each one with its product's name.

  10. 10. Predict the output

    What does this code print?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →