From the course: Advanced Python
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Keyword-only arguments - Python Tutorial
From the course: Advanced Python
Keyword-only arguments
- [Instructor] Another similarity that Python has with some other programming languages is that it provides away for specifying function parameters using keywords. So for example, you can define a function that takes positional arguments along with keyword arguments that take optional values like this. Then, when you want to call the function, you can specify values by position or by keyword. In some cases however, you may want to require the callers of your particular function specify arguments using keywords only in order to provide better readability of the code. So for example, suppose we have a function that performs a critical operation. And it provides an option to suppress exceptions. So one way to write this function would be to specify a regular argument and have it default to a certain value. Now the problem with this approach is that the function can be invoked just by passing a regular positional argument. And since this parameter has a significant effect on how the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.