Skip to main content

Features of Python Version 3.8

Hello folks,
Hope You are doing well. Python Released Version 3.8 with cool new features and changes. Here are some doubt related to New Update:

Should You Update to Latest Version ?

Well, if you are beginner or You do not have a lot of Packages installed in Old/previous version of Python then You should Update to the Python 3.8.
BUT
If you are a python developer and already installed a lot of python library and Packages in old/previous version then The Answer is NO. Python 3.7 is best and compatible with all the Packages of Dev. Some packages like RASA and some Machine Learning Package still not updated with Latest version of Python as per date.if You updated to python 3.8 then some package might not be work properly.

What is the New features in Python 3.8

Here are top 5 Features of Python 3.8
This is The feature #1 . All the feature of Python 3.8 will Publish 1 by 1.

New Features

Assignment expressions

There is new syntax := that assigns values to variables as part of a larger expression. It is affectionately known as “the walrus operator” due to its resemblance to the eyes and tusks of a walrus.

In this example, the assignment expression helps avoid calling len() twice:

if (n := len(a)) > 10:
    print(f"List is too long ({n} elemnts, expected <= 10)")

A similar benefit arises during regular expression matching where match objects are needed twice, once to test whether a match occurred and another to extract a subgroup:

discount = 0.0
if (mo := re.search(r'(\d+)% discount', advertisement)):
    discount = float(mo.group(1)) / 100.0

The operator is also useful with while-loops that compute a value to test loop termination and then need that same value again in the body of the loop:

# Loop over fixed length blocks
while (block := f.read(256)) != '':
    process(block)

Another motivating use case arises in list comprehensions where a value computed in a filtering condition is also needed in the expression body:

[clean_name.title() for name in names
 if (clean_name := normalize('NFC', name)) in allowed_names]

Try to limit use of the walrus operator to clean cases that reduce complexity.


This is The feature #2 .


Reversible dictionary — order

Dictionaries are now iterable in reversed insertion order using reversed().

This is The feature #3 .

New modules — metadata

There is a new importlib.metadata module that allows you to read metadata from third-party packages. You can extract version numbers of packages in your scripts.

This is The feature #4 . 

Continue — finally

It used to be illegal to use continue statement in a finally clause due to a problem with the implementation. Not anymore.

This is The feature #5 .

Positional-only parameters

There is a new function parameter syntax / to indicate that some function parameters must be specified positionally and cannot be used as keyword arguments. This is the same notation shown by help() for C functions annotated with Larry Hastings’ Argument Clinic tool.

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:

def f(a, b, /, c, d, *, e, f):
    print(a, b, c, d, e, f)

The following is a valid call:

f(10, 20, 30, d=40, e=50, f=60)

However, these are invalid calls:

f(10, b=20, c=30, d=40, e=50, f=60)   # b cannot be a keyword argument
f(10, 20, 30, 40, 50, f=60)           # e must be a keyword argument

One use case for this notation is that it allows pure Python functions to fully emulate behaviors of existing C coded functions. For example, the built-in divmod() function does not accept keyword arguments:

def divmod(a, b, /):
    "Emulate the built in divmod() function"
    return (a // b, a % b)

Another use case is to preclude keyword arguments when the parameter name is not helpful. For example, the builtin len() function has the signature len(obj, /). This precludes awkward calls such as:

len(obj='hello')  # The "obj" keyword argument impairs readability

A further benefit of marking a parameter as positional-only is that it allows the parameter name to be changed in the future without risk of breaking client code. For example, in the statistics module, the parameter name dist may be changed in the future. This was made possible with the following function specification:

def quantiles(dist, /, *, n=4, method='exclusive')
    ...

Since the parameters to the left of / are not exposed as possible keywords, the parameters names remain available for use in **kwargs:

>>>
>>> def f(a, b, /, **kwargs):
...     print(a, b, kwargs)
...
>>> f(10, 20, a=1, b=2, c=3)         # a and b are used in two ways
10 20 {'a': 1, 'b': 2, 'c': 3}

This greatly simplifies the implementation of functions and methods that need to accept arbitrary keyword arguments. For example, here is an excerpt from code in the collections module:

class Counter(dict):

    def __init__(self, iterable=None, /, **kwds):
        # Note "iterable" is a possible keyword argument

Comments

Popular posts from this blog

Facebook is testing ‘Green Screen’ editing tool for content creators

"Green Screen" will be available as an editing tool for the social media app whereas on Instagram it is available as an AR filter or effect." Facebook is testing a new feature for creators. The new “Green Screen” tool will allow users to add any video or image in the background of the Facebook Stories they create. This option is similar to the one available on Instagram already. However, it will be available as an editing tool for the social media app, whereas on Instagram it is available as an AR filter or effect. This tool was spotted by Mamun Billah via Social Media Today. As per the screenshot shared, the user can see the option in the stories section. The user can choose a photo or video from the Gallery section. When the user chooses the option, it is also labelled as “GREEN SCREEN by Instagram” at the bottom. Here’s the screenshot of the feature Green screen feature comes to facebook stories section! @MattNavarra pic.twitter.com/np9uMuQJaZ — Mamun Billah (@mamun...

Python program to print and add numbers starting 1 onwards till the sum of them is less than 100

Below is the code snippet to print the sum of number from 1 to 100 in Python. Check the indents. #Declaring Variable  sum=0  #Now Running For Loop from 1 to 100   #range(0,n) take 0 and leave the last element 'n'  for i in range (1,101):  #Checking weather sum is less than 100 or not       while((sum+i)<100):           sum+=i           print(sum,'\n')           #Once Printed Sum Now Break The While Loop           break #End Of Program #END OF THE PROGRAM

Java or C++?

Which programming language should I choose ? H ey Folks, If you are reading this blog, most probably you are going to start Competitive coding or you are initiating the journey of programmar. Or maybe you are a professional, Engineer well never mind. In this blog, I will explain to you the keypoint and language you should choose for your Programming Journey or for your Competitive Journey. To the point, if you are planning to start Competitive Programming , and no prior Kowlege of JAVA and I am assuming you are completely beginner, then without any doubt go for C++ . Why I am saying so, let me explain it in the simplest way. In CPP, you can use a lot of libraries helpful in competitive coding, and most important C++ is the most reliable and low latency language. when you will use the STL library to implement your code then you will fall in love with C++.You can easily use the property of Stack, Queue, and Priority Queue using STL and when it comes to program latency ...