Functions
Functions with optional parameters
|
In Python, we can create functions with optional parameters by providing default values for the parameters in the function definition. If a value for the parameter is not required inside the function, we typically set the default value to When the function is called, if an argument is passed, the function will use it. If no argument is passed, the parameter will default to In the following example, the first time we call the function, we pass it an argument that is a variable containing a name. The second time we call the function, we do not pass it an argument, and so the parameter defaults to |
|
Run the following code
In the previous example, the default value for the parameter was If you call the function without passing it an argument, it will use the default value that was specified in the function definition.
|