HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-02-21
1 <p>In programming, many functions and methods have parameters that rarely change. In such cases, we work with these parameters and give them default values that we can rewrite later. It reduces the amount of code that looks the same. Let's look at what it looks like in practice.</p>
1 <p>In programming, many functions and methods have parameters that rarely change. In such cases, we work with these parameters and give them default values that we can rewrite later. It reduces the amount of code that looks the same. Let's look at what it looks like in practice.</p>
2 <p>Let's look at an example:</p>
2 <p>Let's look at an example:</p>
3 <p>The default value looks like a regular assignment within the definition. It's only triggered if we do not pass the parameter.</p>
3 <p>The default value looks like a regular assignment within the definition. It's only triggered if we do not pass the parameter.</p>
4 <p>Suppose you forgot to take parts for your car to the repair shop. In this case, the repairman will offer to use default parts - ones he already has in stock.</p>
4 <p>Suppose you forgot to take parts for your car to the repair shop. In this case, the repairman will offer to use default parts - ones he already has in stock.</p>
5 <p>There can even be a default value when there is only one parameter:</p>
5 <p>There can even be a default value when there is only one parameter:</p>
6 <p>There can be any number of parameters with default values:</p>
6 <p>There can be any number of parameters with default values:</p>
7 <p>The default values have one restriction. They must be at the very end of the parameter list. From a syntax standpoint, it's impossible to create a function with an optional parameter followed by a mandatory one:</p>
7 <p>The default values have one restriction. They must be at the very end of the parameter list. From a syntax standpoint, it's impossible to create a function with an optional parameter followed by a mandatory one:</p>
8 <p>Now you know how to work with default values. They can be in several parameters or just one. And remember that the default values should be at the very end of the parameter list. It will help prevent lots of identical code from piling up.</p>
8 <p>Now you know how to work with default values. They can be in several parameters or just one. And remember that the default values should be at the very end of the parameter list. It will help prevent lots of identical code from piling up.</p>
9 <h2>The variable number of parameters</h2>
9 <h2>The variable number of parameters</h2>
10 <p>Some functions are different since they take a variable number of parameters. And we're not talking about default values. Check out this example:</p>
10 <p>Some functions are different since they take a variable number of parameters. And we're not talking about default values. Check out this example:</p>
11 <p>In the above example, the max() function finds the maximum value among the passed parameters. You can examine the<a>Python documentation</a>and learn how many parameters we can pass to the function.</p>
11 <p>In the above example, the max() function finds the maximum value among the passed parameters. You can examine the<a>Python documentation</a>and learn how many parameters we can pass to the function.</p>
12 <p>You will see this construction:</p>
12 <p>You will see this construction:</p>
13 <p>It means that max() takes two or more parameters as input:</p>
13 <p>It means that max() takes two or more parameters as input:</p>
14 <p>If the function finds several parameters with the maximum value, it will return the first one.</p>
14 <p>If the function finds several parameters with the maximum value, it will return the first one.</p>