{"id":1119,"date":"2023-06-05T15:54:00","date_gmt":"2023-06-05T10:24:00","guid":{"rendered":"https:\/\/geekpython.in\/?p=1119"},"modified":"2024-03-16T22:48:26","modified_gmt":"2024-03-16T17:18:26","slug":"asterisk-in-python","status":"publish","type":"post","link":"https:\/\/geekpython.in\/asterisk-in-python","title":{"rendered":"Understanding the Different Uses of the Asterisk(*) in Python"},"content":{"rendered":"\n<p>You must have seen the asterisk or star symbol inside the parameterized function or used it to perform mathematical or other high-level operations.<\/p>\n\n\n\n<p>We&#8217;ll look at the different ways the asterisk(<code>*<\/code>) is used in Python in this article.<\/p>\n\n\n\n<p>Asterisks(<code>*<\/code>) are used in the following situations:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Exponentiation and multiplication<\/li>\n\n\n\n<li>Unpacking\/Packing<\/li>\n\n\n\n<li>Repetition<\/li>\n\n\n\n<li>Formatting Strings<\/li>\n\n\n\n<li>Tuple and Set Unpacking<\/li>\n\n\n\n<li>Asterisk to Bound Function&#8217;s Parameters to the keyword-only Argument<\/li>\n<\/ul>\n\n\n\n<p>Let&#8217;s begin by breaking down the use of asterisks in the above cases one by one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-multiplication\"><a href=\"https:\/\/geekpython.in\/asterisk-in-python#heading-multiplication\"><\/a>Multiplication<\/h2>\n\n\n\n<p>Python has arithmetic operators, one of which is an asterisk(<code>*<\/code>), which is commonly used to perform multiplication operations.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Multiplication using asterisk(*)\nmultiply = 9 * 7\nprint(multiply)\n\n---------\n63<\/pre><\/div>\n\n\n\n<p>In the above code, we performed a simple arithmetic operation by multiplying&nbsp;<code>9<\/code>&nbsp;and&nbsp;<code>7<\/code>&nbsp;using the asterisk(<code>*<\/code>) as the multiplication operator.<\/p>\n\n\n\n<p>And we can do this also.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">def multiply(a, b):\n    return a * b\n\nproduct = multiply(\"Geek\", 5)\nprint(product)\n\n----------\nGeekGeekGeekGeekGeek<\/pre><\/div>\n\n\n\n<p>The above code defines the function&nbsp;<code>multiply<\/code>, which takes two parameters&nbsp;<code>a<\/code>&nbsp;and&nbsp;<code>b<\/code>, and returns the product of&nbsp;<code>a<\/code>&nbsp;and&nbsp;<code>b<\/code>&nbsp;multiplied.<\/p>\n\n\n\n<p>We multiplied the&nbsp;<code>\"Geek\"<\/code>&nbsp;and&nbsp;<code>5<\/code>&nbsp;arguments and printed the result. As we can see in the output, the argument&nbsp;<code>\"Geek\"<\/code>&nbsp;was multiplied by&nbsp;<code>5<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-exponentiation\"><a href=\"https:\/\/geekpython.in\/asterisk-in-python#heading-exponentiation\"><\/a>Exponentiation<\/h2>\n\n\n\n<p>Similarly, we can use the asterisk to perform an exponentiation operation, but to get the exponential value of an integer, we must use a double asterisk(<code>**<\/code>).<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Exponentiation using asterisk(*)\nexpo = 4 ** 4\nprint(expo)\n\n----------\n256<\/pre><\/div>\n\n\n\n<p>We obtained&nbsp;<code>256<\/code>&nbsp;as the result of evaluating&nbsp;<code>4<\/code>&nbsp;raised to power&nbsp;<code>4<\/code>(<code>4**4<\/code>). The double asterisk(<code>**<\/code>) is also known as the power operator.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-packing-and-unpacking\"><a href=\"https:\/\/geekpython.in\/asterisk-in-python#heading-packing-and-unpacking\"><\/a>Packing and Unpacking<\/h2>\n\n\n\n<p>Before we begin, we must understand that there are two types of arguments:&nbsp;<strong>positional<\/strong>&nbsp;arguments and&nbsp;<strong>keyword<\/strong>&nbsp;arguments.<\/p>\n\n\n\n<p><strong>Positional<\/strong>&nbsp;<strong>arguments<\/strong>&nbsp;are passed to the function based on their position, whereas&nbsp;<strong>keyword<\/strong>&nbsp;<strong>arguments<\/strong>&nbsp;are passed to the function based on their parameter name.<\/p>\n\n\n\n<p>Consider the following example of positional and keyword arguments.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Positional and Keyword arguments\ndef friends(f1, f2, f3=None, f4=None):\n    return f1, f2, f3, f4\n\n# Passing two positional and two keyword argument\nnames = friends(\"Rishu\", \"Yashwant\", f3=\"Abhishek\", f4=\"Yogesh\")\nprint(names)\n\n# Passing keyword argument before the possitional argument\nnames1 = friends(\"Rishu\", f4=\"Yogesh\", \"Yashwant\")\nprint(names1)<\/pre><\/div>\n\n\n\n<p>The function&nbsp;<code>friends<\/code>&nbsp;in the above code take two positional arguments,&nbsp;<code>f1<\/code>&nbsp;and&nbsp;<code>f2<\/code>, and two keyword arguments,&nbsp;<code>f3<\/code>&nbsp;and&nbsp;<code>f4<\/code>, with a default value of&nbsp;<code>None<\/code>.<\/p>\n\n\n\n<p>In the first case, we used two positional arguments&nbsp;<code>\"Rishu\"<\/code>&nbsp;and&nbsp;<code>\"Yashwant\"<\/code>&nbsp;and two keyword arguments&nbsp;<code>f3=\"Abhishek\"<\/code>&nbsp;and&nbsp;<code>f4=\"Yogesh\"<\/code>&nbsp;to call the function.<\/p>\n\n\n\n<p>You can see how&nbsp;<code>\"Rishu\"<\/code>&nbsp;and&nbsp;<code>\"Yashwant\"<\/code>&nbsp;were passed into the position of&nbsp;<code>f1<\/code>&nbsp;and&nbsp;<code>f2<\/code>, respectively, and&nbsp;<code>\"Abhishek\"<\/code>&nbsp;and&nbsp;<code>\"Yogesh\"<\/code>&nbsp;were passed with the parameter names&nbsp;<code>f3<\/code>&nbsp;and&nbsp;<code>f4<\/code>. However, we cannot change the position, as we did in the second case by passing the keyword argument before the positional argument; doing so will result in a&nbsp;<code>SyntaxError<\/code>.<\/p>\n\n\n\n<p>If we try to pass an arbitrary number of arguments inside the function&nbsp;<code>friends<\/code>, we will get an error. As a result, we need a way to pass variadic arguments within the function.<\/p>\n\n\n\n<p>We can use&nbsp;<code>*args<\/code>&nbsp;and&nbsp;<code>**kwargs<\/code>&nbsp;to pass variadic arguments in situations where we need to.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-geekpython-python-programming-tutorials wp-block-embed-geekpython-python-programming-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"oceanwp-oembed-wrap clr\"><blockquote class=\"wp-embedded-content\" data-secret=\"U3th93OCsE\"><a href=\"https:\/\/geekpython.in\/understanding-args-and-kwargs-in-python-best-practices-and-guide\">Understanding args and kwargs in Python: Best Practices and Guide<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Understanding args and kwargs in Python: Best Practices and Guide&#8221; &#8212; GeekPython - Python Programming Tutorials\" src=\"https:\/\/geekpython.in\/understanding-args-and-kwargs-in-python-best-practices-and-guide\/embed#?secret=rIZVKlbLvV#?secret=U3th93OCsE\" data-secret=\"U3th93OCsE\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/div>\n<\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-argument-packing\"><a href=\"https:\/\/geekpython.in\/asterisk-in-python#heading-argument-packing\"><\/a>Argument Packing<\/h3>\n\n\n\n<p><strong>Passing variadic positional arguments<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Use of *args\ndef friends(*args):\n    return args\n\n# Passing variadic positional arguments\nnames = friends(\"Rishu\", \"Yashwant\", \"Abhishek\", \"Yogesh\")\nprint(names)\n\n----------\n('Rishu', 'Yashwant', 'Abhishek', 'Yogesh')<\/pre><\/div>\n\n\n\n<p>The function&nbsp;<code>friends<\/code>&nbsp;takes&nbsp;<code>*args<\/code>, indicating that the function accepts a variable number of positional arguments. We passed an arbitrary number of positional arguments, which were saved in the tuple called&nbsp;<code>args<\/code>.<\/p>\n\n\n\n<p><strong>Passing variadic keyword arguments<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Use of **kwargs\ndef friends(**kwargs):\n    return kwargs\n\n# Passing variadic keyword arguments\nnames = friends(f1=\"Rishu\", f2=\"Yashwant\", f3=\"Abhishek\")\nprint(names)<\/pre><\/div>\n\n\n\n<p>This time function accepts&nbsp;<code>**kwargs<\/code>, indicating that it accepts an arbitrary number of keyword arguments. We passed an arbitrary number of keyword arguments, which were saved in the dictionary called&nbsp;<code>kwargs<\/code>.<\/p>\n\n\n\n<p>As a result, we can conclude that the asterisks with args and kwargs were used to pack the arguments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-unpacking\"><a href=\"https:\/\/geekpython.in\/asterisk-in-python#heading-unpacking\"><\/a>Unpacking<\/h3>\n\n\n\n<p>We have used single and double asterisks as packing operators with args and kwargs, respectively, and we can also use them for unpacking.<\/p>\n\n\n\n<p>The iterables are unpacked with a single asterisk(<code>*<\/code>), while the dictionaries are unpacked with a double asterisk(<code>**<\/code>).<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># List of names\nnames_lst = [\"Sachin\", \"Rishu\", \"Yashwant\", \"Abhishek\"]\n\ndef greet(*names):\n    for name in names:\n        print(f'Welcome to GeekPython, {name}.')\n\nmessage = greet(*names_lst)<\/pre><\/div>\n\n\n\n<p>We have a list of names and a function&nbsp;<code>greet<\/code>&nbsp;that accepts a variable number of positional arguments and iterates through them to print some information.<\/p>\n\n\n\n<p>You&#8217;ll notice that we passed&nbsp;<code>names_lst<\/code>&nbsp;as&nbsp;<code>*names_lst<\/code>&nbsp;because this will unpack the items in the&nbsp;<code>names_lst<\/code>&nbsp;list.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Welcome to GeekPython, Sachin.\nWelcome to GeekPython, Rishu.\nWelcome to GeekPython, Yashwant.\nWelcome to GeekPython, Abhishek.<\/pre><\/div>\n\n\n\n<p>If we had passed the&nbsp;<code>names_lst<\/code>&nbsp;to the function, we would have gotten the following result.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">message = greet(names_lst)\n\n----------\nWelcome to GeekPython, ['Sachin', 'Rishu', 'Yashwant', 'Abhishek'].<\/pre><\/div>\n\n\n\n<p>Similarly, we can unpack the dictionaries by using a double asterisk(<code>**<\/code>). Let us illustrate with an example.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Dictionary with name and roles\nocc_dict = {\n    \"Sachin\": \"Python dev\", \n    \"Rishu\": \"C++ dev\", \n    \"Yashwant\": \"C++ dev\", \n    \"Abhishek\": \"PHP dev\"\n}\n\ndef occupation(**roles):\n    for key, value in roles.items():\n        print(f\"{key} is a {value}.\")\n\noccupation(**occ_dict)<\/pre><\/div>\n\n\n\n<p>The function&nbsp;<code>occupation<\/code>&nbsp;accepts&nbsp;<code>**roles<\/code>, which means we can pass an arbitrary number of keyword arguments when calling the function, and it then iterates through the key and value and prints them.<\/p>\n\n\n\n<p>We called the function and passed the dictionary&nbsp;<code>occ_dict<\/code>&nbsp;prefixed with a double asterisk(<code>**<\/code>). This will unpack the dictionary&#8217;s keys and values, producing the output shown below.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Sachin is a Python dev.\nRishu is a C++ dev.\nYashwant is a C++ dev.\nAbhishek is a PHP dev.<\/pre><\/div>\n\n\n\n<p>Alternatively, we can pass the keyword arguments in the function call as shown below.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">occupation(Sachin=\"Python dev\", Rishu=\"C++ dev\")\n\n----------\nSachin is a Python dev.\nRishu is a C++ dev.<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-repetition-of-list-and-string\"><a href=\"https:\/\/geekpython.in\/asterisk-in-python#heading-repetition-of-list-and-string\"><\/a>Repetition Of List And String<\/h2>\n\n\n\n<p>We can use an asterisk as a repetition operator, repeating the string or list for a specific number (similar to multiplying them). Let&#8217;s understand with an example.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Using asterisk as a repetition operator\ndata = \"GeekPython\" * 3\nprint(data)\n\nprint(\"-\" * 20)\n\nlst_data = [\"Geek\", \"Python\"] * 3\nprint(lst_data)<\/pre><\/div>\n\n\n\n<p>In the above code, we are essentially multiplying or repeating whatever you want to call it. The output will be the string and list being repeated three times.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">GeekPythonGeekPythonGeekPython\n--------------------\n['Geek', 'Python', 'Geek', 'Python', 'Geek', 'Python']<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-asterisk-in-string-formatting\"><a href=\"https:\/\/geekpython.in\/asterisk-in-python#heading-asterisk-in-string-formatting\"><\/a>Asterisk In String Formatting<\/h2>\n\n\n\n<p>You must have used different methods to format the strings in Python. We can use the asterisk in string formatting to unpack the tuples\/lists values.<\/p>\n\n\n\n<p>We&#8217;ll use the&nbsp;<code>.format<\/code>&nbsp;string formatting method.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Using asterisk in string formatting\n\n# Unpacking list\ndata = \"{} {} {}.\".format(*[\"Welcome\", \"to\", \"GeekPython\"])\nprint(data)\n\n# Unpacking tuple\nval = \"{} {} {}.\".format(*(1, 2, 3))\nprint(val)<\/pre><\/div>\n\n\n\n<p>In the above code, we are just unpacking the list and tuple values using the single asterisk(<code>*<\/code>) passed within the&nbsp;<code>.format<\/code>&nbsp;string formatting.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Welcome to GeekPython.\n1 2 3.<\/pre><\/div>\n\n\n\n<p>This can only be used with the&nbsp;<code>.format<\/code>&nbsp;string formatting method, and the goal here is simply to demonstrate how we can use an asterisk while formatting strings.<\/p>\n\n\n\n<p>Asterisks are not permitted to be used in other string formatting methods.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-tupleset-unpacking\"><a href=\"https:\/\/geekpython.in\/asterisk-in-python#heading-tupleset-unpacking\"><\/a>Tuple\/Set Unpacking<\/h2>\n\n\n\n<p>We learned earlier in this article how to use&nbsp;<code>*<\/code>&nbsp;asterisks to unpack the iterable and&nbsp;<code>**<\/code>&nbsp;asterisks to unpack the dictionary. In this section, we&#8217;ll use the asterisk to unpack the values contained within the tuple\/set.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">x = {'One', 'piece', 'is', 'real'}\nprint(type(x))\nprint(*x)\n\n----------\n&lt;class 'set'&gt;\nOne real is piece<\/pre><\/div>\n\n\n\n<p>The set&nbsp;<code>{'One', 'piece', 'is', 'real'}<\/code>&nbsp;is unpacked into&nbsp;<code>One piece is real<\/code>&nbsp;in the preceding example.<\/p>\n\n\n\n<p>Here&#8217;s an example of how to unpack a tuple.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">x, *y, z = ('One', 'piece', 'is', 'real')\nprint(x)\nprint(y)\nprint(z)\n\n----------\nOne\n['piece', 'is']\nreal<\/pre><\/div>\n\n\n\n<p>The output shows that the tuple unpacks into\u00a0<code>x=One<\/code>,\u00a0<code>y=['piece', 'is']<\/code>, and\u00a0<code>z=real<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Asterisk to Bound Function&#8217;s Parameters to the keyword-only Argument<\/h2>\n\n\n\n<p>You might have seen a bare asterisk (<code>*<\/code>) in a function&#8217;s parameter list. Why bare asterisk is used and what it does?<\/p>\n\n\n\n<p>In short, a bare asterisk (<code>*<\/code>) is used to control how to pass a value as an argument.<\/p>\n\n\n\n<p>Here&#8217;s an example to show when a function has a bare asterisk in the parameter list, what does that imply?<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python mark:2 decode:true \" ># Bare asterisk in function parameter\ndef func(x, y, *, z):\n    pass<\/pre><\/div>\n\n\n\n<p>The function <code>func()<\/code> takes three arguments: <code>x<\/code>, <code>y<\/code>, and <code>z<\/code> but it also has an asterisk (<code>*<\/code>) between the <code>x<\/code>, <code>y<\/code> and <code>z<\/code> parameters.<\/p>\n\n\n\n<p>This means that the parameter on the right side of the asterisk is a keyword-only argument and the parameters on the left side can be passed as either positional or keyword argument.<\/p>\n\n\n\n<p>But the parameter <code>z<\/code> is now obliged to keyword argument and if you pass it as a positional argument, the program will throw an error.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \" ># Bare asterisk in function parameter\ndef func(x, y, *, z):\n    print(x, y, z)\n\nval_1 = func(2, 3, 4)   # Error\nval_2 = func(2, 3, z=4) # Works<\/pre><\/div>\n\n\n\n<p>If you run the code, you&#8217;ll get the following error.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:tex decode:true \" >Traceback (most recent call last):\n  ...\n    val_1 = func(2, 3, 4)\n            ^^^^^^^^^^^^^\nTypeError: func() takes 2 positional arguments but 3 were given<\/pre><\/div>\n\n\n\n<p>It says that the function func takes only two positional arguments but three positional arguments were supplied.<\/p>\n\n\n\n<p>But if you pass <code>z=4<\/code> in the function just like in the <code>val_2<\/code> in the above code, the program will not throw any error.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python mark:6 decode:true \" ># Bare asterisk in function parameter\ndef func(x, y, *, z):\n    print(x, y, z)\n\n# val_1 = func(2, 3, 4)   # Error\nval_2 = func(2, 3, z=4) # Works\n\n--------------------\n2 3 4<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-others\"><a href=\"https:\/\/geekpython.in\/asterisk-in-python#heading-others\"><\/a>Others<\/h2>\n\n\n\n<p>Another application of the asterisk could be in importing all of the classes and functions from the modules.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">from time import *\n\n# Current time in seconds\ncurr_time = time()\nprint(f'Current time in sec: {curr_time}')\n\n# Formatted date and time\nt = strftime(\"%A, %d %B %Y %H:%M:%S\")\nprint(t)\n\n----------\nCurrent time in sec: 1685963439.6365585\nMonday, 05 June 2023 16:40:39<\/pre><\/div>\n\n\n\n<p>We were able to use the&nbsp;<code>time<\/code>&nbsp;and&nbsp;<code>strftime<\/code>&nbsp;functions from the&nbsp;<code>time<\/code>&nbsp;module because of the asterisk, which helps in the import of all functions and classes from the module.<\/p>\n\n\n\n<p>Note: This is not a good practice at all, importing all the classes and functions from the module at a time can use up resources unnecessarily.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-conclusion\"><a href=\"https:\/\/geekpython.in\/asterisk-in-python#heading-conclusion\"><\/a>Conclusion<\/h2>\n\n\n\n<p>This article explains the use of asterisks in Python. We can use it as a multiplication operator or to pack and unpack arguments.<\/p>\n\n\n\n<p>Let&#8217;s recall what we&#8217;ve learned:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using asterisk for exponentiation and multiplication<\/li>\n\n\n\n<li>Argument packing\/unpacking<\/li>\n\n\n\n<li>Using as a repetition operator<\/li>\n\n\n\n<li>Using asterisk in the string formatting<\/li>\n\n\n\n<li>Unpacking the tuple and set values<\/li>\n\n\n\n<li>Asterisk to bound function&#8217;s parameters to the keyword-only argument<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\ud83c\udfc6<strong>Other articles you might be interested in if you liked this one<\/strong><\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/init-vs-new\" rel=\"noreferrer noopener\">The concept of constructors and initializers in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/f-string-in-python\" rel=\"noreferrer noopener\">An improved and modern way of string formatting<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/access-modifiers-in-python\" rel=\"noreferrer noopener\">Public, Protected, and Private access modifiers in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/class-inheritance-in-python\" rel=\"noreferrer noopener\">What are inheritance and different types of inheritance in Python<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/init-and-call-method\" rel=\"noreferrer noopener\">What do they do &#8211; __init__ and __call__ methods<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/implement-getitem-setitem-and-delitem-in-python\" rel=\"noreferrer noopener\">How to implement __getitem__, __setitem__, and __delitem__ in Python class<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/displaying-images-on-the-frontend-using-fastapi\" rel=\"noreferrer noopener\">Displaying images on the frontend using FastAPI<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>That&#8217;s all for now<\/strong><\/p>\n\n\n\n<p><strong>Keep Coding\u270c\u270c<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You must have seen the asterisk or star symbol inside the parameterized function or used it to perform mathematical or other high-level operations. We&#8217;ll look at the different ways the asterisk(*) is used in Python in this article. Asterisks(*) are used in the following situations: Let&#8217;s begin by breaking down the use of asterisks in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1121,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[2,7],"tags":[12,31],"class_list":["post-1119","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-python-tips","tag-python","tag-python3","entry","has-media"],"_links":{"self":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/1119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/comments?post=1119"}],"version-history":[{"count":7,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/1119\/revisions"}],"predecessor-version":[{"id":1681,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/1119\/revisions\/1681"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media\/1121"}],"wp:attachment":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media?parent=1119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/categories?post=1119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/tags?post=1119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}