<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jordan Williams</title>
    <description>The latest articles on DEV Community by Jordan Williams (@platinumcoder).</description>
    <link>https://dev.to/platinumcoder</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F449990%2F380ab39a-9948-4b3e-9fc3-d67263571831.jpg</url>
      <title>DEV Community: Jordan Williams</title>
      <link>https://dev.to/platinumcoder</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/platinumcoder"/>
    <language>en</language>
    <item>
      <title>Python Features You Should Know (That can Save you A Lot of Time !)</title>
      <dc:creator>Jordan Williams</dc:creator>
      <pubDate>Tue, 19 Jan 2021 05:45:33 +0000</pubDate>
      <link>https://dev.to/platinumcoder/python-features-you-should-know-that-can-save-you-a-lot-of-time-33mf</link>
      <guid>https://dev.to/platinumcoder/python-features-you-should-know-that-can-save-you-a-lot-of-time-33mf</guid>
      <description>&lt;p&gt;Using python over the years, I came across some useful features that would have saved me a lot of time if I had known about them a little bit earlier. These little python gems can help keep your code more DRY( &lt;strong&gt;&lt;em&gt;D&lt;/em&gt;&lt;/strong&gt;o Not &lt;strong&gt;&lt;em&gt;R&lt;/em&gt;&lt;/strong&gt;epeat &lt;strong&gt;&lt;em&gt;Y&lt;/em&gt;&lt;/strong&gt;ourself) and clean.&lt;/p&gt;

&lt;p&gt;By the time you are finished with this article, I can guarantee you that you will be using some of these features in your very own python programs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: You can use any IDE or text editor that you are familiar with ( python’s default IDE is known as “IDLE” and that can also be used). For these features, I will be demonstrating using Visual Studio Code (VS Code) with a python extension.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For maximum appreciation, it would be best if you’ve had some experience in using python. However, even if you have never used python before, this article will help you on your python journey. So sit back, relax and enjoy !&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Enumerate&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let’s first start off with Enumerate.&lt;/p&gt;

&lt;p&gt;Let’s say you had a list of fruits. You also wanted to loop through all the fruits that are in that list and also keep a track of the position(index) of each fruit in that list using a for-loop.&lt;/p&gt;

&lt;p&gt;The following code is an example of this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AXso_Vf1ELO0FY2G5hgf1Mw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AXso_Vf1ELO0FY2G5hgf1Mw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 apple
1 banana
2 mango
3 melon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As you can see we got each fruit in the list with its corresponding index. You could also use a while loop to complete this task but it would also lead to the same issue — a lengthy code .&lt;/p&gt;

&lt;p&gt;A better way to solve this issue is to use enumerate.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AlDMG_XIiLh2hrvpbtcZucw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AlDMG_XIiLh2hrvpbtcZucw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 apple
1 banana
2 mango
3 melon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;See, the output is the same!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We were able to do the same task with less lines of code. But how?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;enumerate(fruit_lst)&lt;/code&gt;. This is where enumerate comes in. Inside our for-loop, &lt;code&gt;enumerate(fruit_lst)&lt;/code&gt; allows us to keep track of the index of each element (fruit). Each iteration in the loop returns a tuple with the first element being the index and the second element being the current element in the list.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;count,fruit&lt;/code&gt; breaks apart that tuple which contains two elements, assigning the first and second element to them respectively.&lt;/p&gt;

&lt;p&gt;It is only fair to imagine that &lt;code&gt;enumerate&lt;/code&gt; turned &lt;code&gt;fruit_lst&lt;/code&gt; into a list of tuples as seen below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[(0,"apple"),(1,"banana"),(2,"mango"),(3,"melon")]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Easier Printing to the Console&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Too many times I have seen developers over complicate printing. Instead of using the typical concatenation or &lt;code&gt;.format()&lt;/code&gt; method of a string, there is a much easier way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AHBtbWAZKNayPruudTBwrhw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AHBtbWAZKNayPruudTBwrhw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Look how clean and simple the code snippet above is. All it requires is an &lt;code&gt;f&lt;/code&gt; before any string.&lt;/p&gt;

&lt;p&gt;Any variable that needs to be in the string can be encased in-between the double curly braces &lt;code&gt;{ }&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10 + 20 = 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Keyword Arguments (**kwargs) and Non-Keyword Arguments(*args)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;You might have come across these two in python’s documentation. A lot of functions in python libraries are implemented using keyword and non-keyword arguments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;The terms parameters and arguments will be used quite frequently throughout this section and onwards in this article. From a function’s perspective:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A parameter is a variable that is listed within the parentheses in a function’s definition. However, an argument is a value that is sent to the function whenever it is called.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AnU5M6nPXbPZlRzXsmQPYaQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AnU5M6nPXbPZlRzXsmQPYaQ.png" alt="parameters vs arguments"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;parameters vs arguments&lt;/p&gt;

&lt;p&gt;Let’s Begin.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Non-Keyword Arguments(*args)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Normally when declaring a function, we have to explicitly declare the number of arguments that are needed for that function.&lt;/p&gt;

&lt;p&gt;The function below adds 3 numbers:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A4KujYblHRnBBeYD9dVVq8w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A4KujYblHRnBBeYD9dVVq8w.png" alt="function to add 3 numbers"&gt;&lt;/a&gt;&lt;em&gt;function to add 3 numbers&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The function above explicitly declares three arguments &lt;strong&gt;a&lt;/strong&gt;, &lt;strong&gt;b&lt;/strong&gt; and &lt;strong&gt;c&lt;/strong&gt;. No arguments apart from those three can be placed within the function.&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;60
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Our output is obvious !&lt;/p&gt;

&lt;p&gt;However, let’s say you had no idea how many numbers you wanted to add. It could have been four numbers, maybe two or even one hundred numbers. We therefore want a multi-purpose function that can handle any number of arguments.&lt;/p&gt;

&lt;p&gt;This is where the non keyword arguments come in (&lt;code&gt;*args&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AvgsHOUshSx4mWy7k_x3dgw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AvgsHOUshSx4mWy7k_x3dgw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6
10
15
21
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As you can see, the function was was able to handle various amounts of numbers that were thrown at it. This works because of the &lt;code&gt;*args&lt;/code&gt; declaration. By placing an asterisk(*) to the left of any variable in a function’s parameters you can achieve this goal.&lt;/p&gt;

&lt;p&gt;It works by storing all the arguments in a tuple that is assigned to a variable defined in the parameters. In this case &lt;code&gt;args&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: &lt;code&gt;args&lt;/code&gt; is an arbitrary name that was given to the variable. Any name could have been used.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you were to print out &lt;code&gt;args&lt;/code&gt; in the console, the final print statement would have be seen as below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(1, 2, 3, 4, 5, 6)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Keyword Arguments&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Up next we have keyword arguments. Keyword arguments can be denoted by key-value pairs inside the function arguments.&lt;/p&gt;

&lt;p&gt;Keyword arguments are similar to non-keyword arguments. However, the only difference found between them is that keyword arguments use double asterisks(**) to the left of the variable name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The function below uses keyword arguments.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ad1AD9rtgksONDhJJpIDZ_g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ad1AD9rtgksONDhJJpIDZ_g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'name': 'jordan', 'age': 10, 'height': 20}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Keyword arguments are supplied with a key and a value that are separated by an equal sign. Similarly to what is shown in the code snippet above. The corresponding key and value are then stored in a dictionary.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Decorators&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Python Decorators. These allow you to add functionalities to an existing function. Decorators allow you to take and modify any function by placing the name of the decorator directly above the function declaration.&lt;/p&gt;

&lt;p&gt;Below is a decorator we named &lt;code&gt;deco&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@deco
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And this is our normal function:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def task1():
    print("task 2")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Running the function above will produce the output seen below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;task 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Decorators are placed on top of the function. The code snippet below shows how decorators are activated:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@deco
def task1():
    print("task 2")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If we were to use this function as is, you will notice something quite interesting.&lt;/p&gt;

&lt;p&gt;The function above will produce the following:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;adding functionality before
task 2
adding functionality after
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Therefore, in adding that decorator we were able to modify the output of the function. But how did this happen?&lt;/p&gt;

&lt;p&gt;Let’s look at how we created this decorator:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A8ODFf5WqdTL8Tz7oqgV9pg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A8ODFf5WqdTL8Tz7oqgV9pg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Let’s start off with the concept that functions in python are “first class objects’’. This is a fancy term that means that functions can basically work like variables. They can be assigned to and provide a return value. You might think that this is the same across each programming language but it is not. Many programming languages such as Java and C cannot do this.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Okay, so with that premise in mind. Let’s look at the function above.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The function name &lt;code&gt;deco&lt;/code&gt; is what we will be calling our decorator.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Whatever function the decorator is attached to it will be stored in the &lt;code&gt;f&lt;/code&gt; variable in the function’s parameters. (Remember, functions in python are first class objects).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;inner&lt;/code&gt; function located inside the &lt;code&gt;deco&lt;/code&gt; function is how we modify the &lt;code&gt;f&lt;/code&gt; function that was passed into the decorator. You can see in the &lt;code&gt;inner&lt;/code&gt; function where we produced two &lt;code&gt;print&lt;/code&gt; statements before and after the function call.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;f()&lt;/code&gt; will call the existing function that was passed into the decorator.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We then return the &lt;code&gt;inner&lt;/code&gt; function. Again, functions are objects so we can return them.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you can see the decorator modified the function and created a new one than performs additional tasks.&lt;/p&gt;

&lt;p&gt;Full code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A87FmjqwVeL6DAwquC1lZsQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A87FmjqwVeL6DAwquC1lZsQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In reality, a decorator is what we call &lt;strong&gt;&lt;em&gt;syntactic sugar&lt;/em&gt;&lt;/strong&gt;. This just means that it is a simpler( and sweeter) way of expressing a piece of code. Let’s look at what decorators really are.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AS1R_lWNw-GwjKy3jEsSEnA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AS1R_lWNw-GwjKy3jEsSEnA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code above does the same task as our code before. However, instead of adding our &lt;code&gt;@deco&lt;/code&gt; to &lt;code&gt;task1()&lt;/code&gt; , we’ve added the &lt;code&gt;task1&lt;/code&gt; function as an argument to our &lt;code&gt;deco&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Decorators are just a cleaner way of achieving the same functionalities.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Adding Parameters to Decorators&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Here’s the thing. Many times functions have parameters. But how do we handle these functions with parameters?&lt;/p&gt;

&lt;p&gt;Let’s add a parameter to our function as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AdR4QRgDGZ7Bwr7LO1SlmUQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AdR4QRgDGZ7Bwr7LO1SlmUQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How do we handle this in our decorator ?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ayrt11YovnxmKDtxAydpcQw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ayrt11YovnxmKDtxAydpcQw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Due to the fact that we are outputting a new function, the new function that we output would need to have the same number of parameters as the function that was inputted. Hence, the &lt;code&gt;inner&lt;/code&gt; function needs to have the same parameters as the function that was inputted.&lt;/p&gt;

&lt;p&gt;The full code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AWwY_W4HN0UQenC_vMbheDg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AWwY_W4HN0UQenC_vMbheDg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;adding functionality before
task 10
adding functionality after
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, we can add parameters. We should be finished, right? Well, one of the points of a decorator and also in every aspect of coding is to ensure reusability. In using and defining strict parameters to the &lt;code&gt;inner&lt;/code&gt; function, we’ve forced the decorator to only accept functions with one parameter. This is not very DRY (&lt;strong&gt;&lt;em&gt;D&lt;/em&gt;&lt;/strong&gt;o Not &lt;strong&gt;&lt;em&gt;R&lt;/em&gt;&lt;/strong&gt;epeat &lt;strong&gt;&lt;em&gt;Y&lt;/em&gt;&lt;/strong&gt;ourself ) of our code.&lt;/p&gt;

&lt;p&gt;To achieve a decorator that will accept various numbers of parameters we will revisit one of the tools we recently just learnt. Our keyword and non-keyword arguments.&lt;/p&gt;

&lt;p&gt;With the combination of these two, this will allow the decorator to not be limited by any number of parameters.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AbugMjG4nqkKH_2sGq3ixEA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AbugMjG4nqkKH_2sGq3ixEA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we fixed our dilemma by adding &lt;code&gt;(*args,**kwargs)&lt;/code&gt; to both our &lt;code&gt;inner&lt;/code&gt; function declaration and our f function call. We then added &lt;code&gt;*args&lt;/code&gt; to allow the function to have multiple parameters and &lt;code&gt;**kwargs&lt;/code&gt; for if and when we decided on using any default parameters or key-value pairs.&lt;/p&gt;

&lt;p&gt;Now let’s try our decorator with two functions that contain different parameters:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVKG1wDKsAzISdOC1rlM5ig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVKG1wDKsAzISdOC1rlM5ig.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;adding functionality before
task 1
adding functionality after
adding functionality before
task 3
adding functionality after
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Thank You For Reading 😃 | Hope you learned something&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/PlatinumCoder" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.buymeacoffee.com%2Fbuttons%2Fv2%2Fdefault-yellow.png" alt="Buy Me A Coffee"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Summary&lt;/strong&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;Simplicity at its best !&lt;/strong&gt;
&lt;/h1&gt;
&lt;/blockquote&gt;

&lt;p&gt;Often times in coding, a complex task can be broken down into simpler ones — you just have to look ! It’s the same thing with these python gems as they are coding hacks to help you on your coding journey to make your code easier to read as well as to be more DRY. I definitely encourage you to try these out whenever you’re writing your own python programs.&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Python Testing: Creating unit test in python</title>
      <dc:creator>Jordan Williams</dc:creator>
      <pubDate>Thu, 22 Oct 2020 15:23:18 +0000</pubDate>
      <link>https://dev.to/platinumcoder/python-testing-53p9</link>
      <guid>https://dev.to/platinumcoder/python-testing-53p9</guid>
      <description>&lt;p&gt;As developers or programmers, call yourself anyone. As long as you write code there is often one thing that gets overlooked. Testing. Testing is that part of development where you’re suppose to rigorously test your applications to ensure that they meet the required functionalities.&lt;/p&gt;

&lt;p&gt;Let’s start of with why we even do testing in the first place:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The need for less manual testing&lt;/strong&gt;.Because the test cases are pre-written, there is no real reason to conduct manual testing anymore. Most times, especially with large applications you have to run through a lot of stages in the software to test if a certain feature works. This could be avoided with testing. Imagine having to use certain inputs every time your application runs. With testing this would be inputted automatically over each run.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Allows for better structure of your code&lt;/strong&gt;. It is of a best practice to create your test cases before development. This forces you to think of the system as a whole before you start developing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Allows for faster testing in long run&lt;/strong&gt;. When coding, the implementation of a function can change however, the output remains the same. Instead of manually testing this every time a function’s implementation changes, you can simply implement specific test cases that can run multiple test cases at a time.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1307e3a3ldrwip0mmswd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1307e3a3ldrwip0mmswd.png" alt="Monitor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;We will be focusing on a specific type of testing and that is unit testing. This specific type of test is for testing small units of code such as a function or a class.&lt;/p&gt;

&lt;p&gt;To create our unit test we will be using the python standard library &lt;code&gt;unittest&lt;/code&gt;. This way of creating test cases uses OOP(Object Oriented Programming) by creating a class that will house all our test cases. This will allow us to run all the test cases in the class at once.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: You can use any IDE or text editor that your familiar with (default python IDE can be used). For this, I will be demonstrating using Visual Studio Code with a python extension.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will first import our unit test library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;unittest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to make our class declaration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TestingClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;unittest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;TestCase&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that &lt;code&gt;(unittest.TestCase)&lt;/code&gt; is inheritance in python. Essentially giving functionality to the class.&lt;/p&gt;

&lt;p&gt;Inside the class add our first function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_first&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;test_var&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assertEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;test_var&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;self.assertEqual&lt;/code&gt; is a method given by the previously inherited class (unittest.TestCase). This method tests if the 2 variables are equally of the same value.&lt;/p&gt;

&lt;p&gt;Adding our test runner. This is what makes our unit test run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;unittest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what the completed code should look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2jr157xlef58mii3dmnr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2jr157xlef58mii3dmnr.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above code demonstrates testing if 9 + 1 is equal to 11. If you know any basic math you should know that 9+1 = 10. Hence this test case would fail.&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flc2xkxh5c3xhz775rs9i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flc2xkxh5c3xhz775rs9i.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you should have already guessed. Failure!&lt;/p&gt;

&lt;p&gt;The fix is simple. Modify the code to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;test_var&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5tsup1hkrb1qwt46eris.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5tsup1hkrb1qwt46eris.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flbonj194z6pdv5d7n5c6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flbonj194z6pdv5d7n5c6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing Outside Functions
&lt;/h2&gt;

&lt;p&gt;For testing outside of functions, the previous example might not be realistic. Let’s replace the &lt;code&gt;test_var&lt;/code&gt; values to now come from a function. We will add a functional declaration to the top of our file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function adds 2 numbers together. Replace 9 + 2 with the function call &lt;code&gt;add(9,2)&lt;/code&gt; and then run your code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fphjv9ub05331ag3wzftc.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fphjv9ub05331ag3wzftc.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have only implemented one test case so far. Each function/method (both are the same thing in this case) in the &lt;code&gt;TestingClass&lt;/code&gt; represents a single test case.&lt;/p&gt;

&lt;p&gt;Lets add another test case called &lt;code&gt;test_multiple_num_addition&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_multiple_num_addition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;test_var&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assertEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;test_var&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note: All the names of the test cases created should be preceded with the word “test” or else it will not be recognized by the test runner.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your code should look like the following below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7b8ah2tq7sbt3bcng3r6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7b8ah2tq7sbt3bcng3r6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After running:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbopbohe0hjx4mun8e9y2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbopbohe0hjx4mun8e9y2.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will obviously fail because the function parameters only accept 2 arguments. But what if we really wanted to add more numbers?&lt;/p&gt;

&lt;p&gt;This can be solved by doing a change to the add function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the asterisk (*) left of the values argument. This allows you to input multiple arguments as well as allowing the values to be stored as a tuple.&lt;/p&gt;

&lt;p&gt;Your code before execution:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fopiv8jv2glcghezuy44q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fopiv8jv2glcghezuy44q.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your code while being executed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fydq5xonyluh7hz6kamx9.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fydq5xonyluh7hz6kamx9.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And Success!&lt;/p&gt;

&lt;p&gt;Putting an asterisk before your variable in the function parameters is called non keyword arguments. Want more information checkout the article below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Giving testing a try might give your code additional robustness. It also has the benefit of changing the way you approach development. Having a testing mindset can ensure that there are less errors in production and less repetitive manual testing during development.&lt;/p&gt;

&lt;p&gt;If you liked this article and want to support. Buy me a coffee. The link is provided below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/PlatinumCoder" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.buymeacoffee.com%2Fbuttons%2Fv2%2Fdefault-yellow.png" alt="Buy Me A Coffee"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>testing</category>
      <category>tutorial</category>
      <category>oop</category>
    </item>
  </channel>
</rss>
