Python introduces the new function syntax in Python3.8.2 Version, Where we can introduce the
/ forward slash to compare the positional only parameter which comes before the
/ slash and parameters that comes after
* is keyword only arguments. Rest of the arguments that are come between
* can be either positional or keyword type of argument.
That means we can combine positional arguments and regular arguments in such a way all the non-positional argument comes after
def function(a, b, /, c, d, *, e, f): # Function Body pass
Where a and b are positional argument, c and d can be either positional or keyword or e and f are strictly keyword type argument.
In the image given below, we can see that power function is a builtin function in Python’s math library and this function uses
/ slash to enable the positional only argument and now we can implement the same functionality with the help of this version.
Example #1 :
In this example we can see that by using positional only argument we can implement the function with the fixed position as we can say only in built-in functions before this python version. With the help of this, we are able to make our program more robust.
Example #2 :
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.