Passing Multiple Arguments to a Function
If you’ve ever wondered what these peculiar variables are or why your IDE defines them in
main(), then this tutorial is for you. You’ll learn how to use
kwargs in Python to add more flexibility to your functions. In this tutorial, you’re going to learn what
**kwargs actually are and how they allow you to pass multiple arguments or keyword arguments to a function.
01:00 This tutorial assumes that you already know how to define Python functions and work with lists and dictionaries. If you don’t or if you need a refresher, then check out some of the other great tutorials here on realpython.com that cover these topics. So, let’s get started.
This is a simple function that takes two arguments,
b, and returns their sum. This function works fine, but it’s limited to only two arguments. What if you need to sum a varying number of arguments, where the specific number of arguments passed is only determined at runtime?
01:43 Wouldn’t it be great to create a function that could sum all the integers passed to it, no matter how many there are? Of course it would. So keep watching, and I’ll show you how you can do just that.
Become a Member to join the conversation.