Defining Python Functions With Optional Arguments (Summary)
In this course, you learned how to:
- Distinguish between parameters and arguments
- Define functions with optional arguments and default parameter values
- Define functions using
args
andkwargs
- Deal with error messages about optional arguments
For more information on concepts covered in this course, you can check out:
- Defining Your Own Python Function
- How to Write Beautiful Code With PEP 8
- Python Scope & the LEGB Rule: Resolving Names in Your Code
- Python Booleans: Optimize Your Code With Truth Values
- Immutability in Python
- Python args and kwargs: Demystified
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:03 Defining your own function to create self-contained subroutines is one of the key building blocks when writing code. The most useful and powerful functions are those that perform one clear task and that you can use in a flexible manner.
00:17
Using optional arguments is a key technique to achieve this. In this course, you’ve learned what the difference is between parameters and arguments, how to define functions with optional arguments and default parameter values, how to define functions using args
and kwargs
, and how to deal with error messages about optional arguments.
00:41
A good understanding of optional arguments will also help you use functions in the standard library and in other third-party modules. Displaying the documentation for these functions will show you the function signature, from which you’ll be able to identify which arguments are required, which ones are optional, and which ones are args
or kwargs
.
01:00 However, the main skill you’ve learned in this course is to define your own functions. You can now start writing functions with required and optional parameters with a variable number of non-keyword and keyword arguments. Mastering these skills will help you take your Python coding to the next level.
01:19 We hope you found this course useful, and we’ll see you again soon at realpython.com.
Become a Member to join the conversation.