python 3.8.6 Positional-only parameters

The Python 3.8 series is the newest feature release by the Python language, and it contains many updated features. So let’s see the “What is exactly new in python 3.8.6 ?”

python 3.8.6 Positional-only parameters
python 3.8.6 Positional-only parameters

One of the most important feature is python 3.8.6 Positional-only parameters , so let’s see :

In this article, we will learn Positional-only parameter syntax which is a function parameter syntax / to indicate that some function parameters must be specified positionally and cannot be used as keyword arguments.

In the following example, parameters a and b are positional-only, while c or d can be positional or keyword, and e or f are required to be keywords:

Also see : How to create two dimensional array

def f(p, q, /, r, s):

    print(p, q, r, s)

f(10, 20, 30, d=40)

The below example will print out the sum of all the parameters within that function.

import math  

def e(p):

    return p * p

def f(p, q, /, **kwargs):

    sum = p + q 

    for num in kwargs:

        sum += kwargs[num]

    print(sum)

f(2, 3, c=40, d=e(10), e=math .sin(60)) # output 144.695

 Some FAQ about python 3.8.6 Positional-only parameters

What are the positional parameters?

Instead of the single-digit 0 a positional parameter is denoted by one or more digits. It is assigned from the shell’s arguments when it is invoked and may be reassigned using the set builtin command.

What are positional parameters in Python?

Positional-only parameter syntax which is a function parameter syntax / to indicate that some function parameters must be specified positionally and cannot be used as keyword arguments.Positional arguments are arguments that can be called by their position in the function definition.

What are the different types of arguments in Python?

There are basically 5 types of arguments in Python
arbitrary positional arguments.
arbitrary keyword arguments.
default arguments.
keyword arguments.
positional arguments.

Summary :

In this article, we saw the What are positional parameters in Python with a simple example so about this section any query then please comment me.

Also see : decision tree in python

BEST OF LUCK !!!

I am the founder of Pythonslearning, a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

Leave a Comment