Think that you are writing a function that accepts multiple parameters, and there is often a common value for some of these parameters. For instance, you would like to be able to call the function without explicitly defining every parameter. In other words, you would like some parameters to have default arguments.

Next, you will be introduced to how to write a function with default arguments and flexible arguments, which allows you to pass any number of arguments to a function.

Prerequisites

If you do not familiar with defining your own function, the article below will give you more information about it.

Writing Your Own Functions

A data scientist will need functions that have specific functionality

towardsdatascience.com

Scope of Variable and LEGB Rule

The scope of a variable refers to the places that you can see or access a variable

towardsdatascience.com


Image for post

Function with default argument value. Image by Author

First, to define a function with a default argument value. In the function header, we attach the parameter of interest with an equals sign and the default argument value. Notice that this function calculates the first argument to the power of the second argument, and the default second argument value is 1. This means we can call the function with two arguments as you would expect. However, if you only use one argument, the function call will use the default argument of 1 for the second parameter.

#software-engineering #data-science #technology #software-development #programming #function

Function Arguments: Default, Keyword, and Arbitrary
1.30 GEEK