From the course: Transition from C# to 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 parameters

Keyword-only parameters

From the course: Transition from C# to Python

Start my 1-month free trial

Keyword-only parameters

- [Instructor] In some cases you may want to require that callers of your functions specify certain arguments using keywords only in order to provide better readability of the code. So let's open up keyword_start.py. Suppose we have a function that performs some type of critical operation and it provides an option to suppress exceptions. So one way to write the 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. Now, since this parameter has a significant effect on how the function executes, it might be better to require that the parameter be specified by keyword. So this way, the function caller is aware of the significance of the parameter and others who read the code can easily see and understand what's happening. So to accomplish this in Python three, you can…

Contents