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

Among Us: New hack ruins the fun as Crewmates start using vents

Among Us is being plagued by a new hack, which is ruining the fun for players. The new hack allows Crewmates to jump in and out of vents, further misleading the identity of the Impostor. As Among Us turned into one of the most popular online games to play in 2020, the flow of hackers and cheaters into the game has also seen a massive rise. This time, the hackers have brought forward an innovative touch to their malicious acts, allowing Crewmates in Among Us to use vents. The globally recognized game based on deception and manipulation enables Impostors in the game to use vents to travel across rooms with ease or even hide after committing the heinous crime of murder. However, venting has its own set of drawbacks as anyone caught going into or coming out of a vent can be easily deduced to be an Impostor. That being said, the hackers in Among Us have managed to hack the game in such a manner that allows Crewmates to use vents. New Among Us hack ruins the fun for many players As visi...

Machine Learning - Explained in easiest way

Machine Learning in Daily Life! When you hear the term Machine Learning, At once you imagine Robots and Some messy algorithms.  Well, Your Imagination is not wrong though. Let me get to the point. Machine Learning is not only about Robots, we see the application of ML in Our Daily Life, even we use it to get better performance or results! Surprised? So Hi, This is Mayank, An Machine Learning enthusiast, and Computer Science Student. In this blog, You will know the Machine Learning and the applications of it in our daily life. Well. Let me give you an example of it. Do you shop online.,  I believe you do. Did you notice, if you are buying a mobile phone then you get a suggestion to buy Mobile Cover too! Let us take another example of Google Photos, You have google photos on Your phone right? When you search some specific keywords like 'Garden', 'Memes', 'Screenshot'  Google Photos give you Images containing those specific visions. These all things possible to hap...

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...