• Home
  • Categories
  • Video Tutorials
    • Angular 5
  • News
  • About us
  • Contact us
  • Login
test
Code4Developers

Code4Developers

Code4Developers
  • Home
  • Categories
  • Video Tutorials
    • Angular 5
  • News
  • About us
  • Contact us
  • Login
  • Python

Must Read | Python 3.9 is released | Read about newly added functionalities

  • Shyam Desai
  • July 15, 2020
  • 3 minute read
3.9
Total
0
Shares
0
0
0

This article would be interesting for you because we are discussing the new functionalities of the newly released python version which is Python 3.9.
It has more capabilities than the older versions. Let’s start.
Firstly python 3.9 was begun to develop from 4th June 2019. This article is about python Beta 4.0 and the version is scheduled as below

3.9.0 beta 5: Monday, 2020-07-20
3.9.0 candidate 1: Monday, 2020-08-10
3.9.0 candidate 2: Monday, 2020-09-14
3.9.0 final: Monday, 2020-10-05
so on 5th October 2020, we can use the final version of python 3.9.0. Let’s see some of the newly added features in short. So let’s get started.

String methods to remove prefixes and suffixes:

Two new functions added 1)removeprefix() 2)removesuffix().

1)removeprefix()

This function is added to remove the prefix from a string if it exists in the string. Otherwise, return the whole string as it is.

Example :

#with the current version:
if test_function_name.startswith(“test_”):
print(test_function_name[5:])
else:
print(test_function_name)

#with py3.9 version

print(test_function_name.removeprefix(“test_”))

2)removesuffix()

This function is added to remove the suffix from a string if it exists in the string. Otherwise, return the whole string as it is.

#with the current version:

def strip_quotes(text):

    if text.startswith('"'):                       
        text = text[1:]                         
    if text.endswith('"'):                      
        text = text[:-1]                        
    return text                                 

#with py3.9 version

def strip_quotes(text):                               
    return text.removeprefix('"').removesuffix('"')   

why these functions are added:-

1)The code will not depend on the user to count the length of a literal.

2)The code does not require a call to the Python built-in len function nor to the more expensive str.replace() method. so performance will be increased.

3)he methods give a higher-level API for code readability as opposed to the traditional method of string slicing.

Add Union Operators To dict:

The PSF(Python Software Foundation) which is responsible for python development has added to more operators for dictionary data-structure for merging and updating the dictionary. These operators are added to the dict class. Lest’s see.

Dictionary Merge or Union operator (|) and Update operator (|=)

  • older versions:

dic1 = {0:1, 1:1}

dic2 = {1:2, 2:3}

d3 = d1.copy()

d3.update(d2)

#Second Way to merge

dic1 = {0:1,  1:1}

dic2 = {1:2,  2:3}

dic3 = {**d1,  **d2}

in both snippets, the values of d1 with equal keys as in d2 are updated by the values of d2. That’s the standard behavior of dictionaries: The last added value for a key wins.

  • With Python 3.9 version you can write as below

dic1 = {0:1, 1:1}

dic2 = {1:2, 2:3}

dic3 = {2:4, 0:4}

#merge dic1 and dic2

merge = dic1 | dic2

#update dic1 with values of dic3

dic1 |= dic3

Here, Be Careful dic1 |= dic3 is different from dic3 |= dic1. since keys that appear in both operands will be updated with the values of the second operand.

A lot of changes are there in the newer version but most of the time or daily routine we use the above things. But a little bit of information I give about other things as below.

Built-in Generic types:-

  • In type annotations you can now use built-in collection types such as list and dict as generic types instead of importing the corresponding capitalized types(e.g List or Dict)from typing. Some other types in the standard library are also now generic, for example, queue.Queue.

New Modules: zoneinfo and graphilb

  • The zoneinfo module brings support for the IANA time zone database to the standard library. It adds zoneinfo.Zoneinfo, a concrete datetime.tzinfo implementation backed at the system’s time zone data
  • Add the graphlib that contains the graphlib.TopolicalSorter class to offer functionality to perform topological sorting of graphs. Here topological sorting is nothing but Directed Acyclic Graph(DAG).

A deep understanding of the newly python version can be read from python.org site.

Thank you for reading the article and stay tuned for new python articles.

Shyam Desai
Shyam Desai

An enthusiastic python based full-stack web-developer and possessing vast knowledge
in python programming language with django,the highly scalable web-framework and good debugging skill in projects as well as possessing knowledge in new technologies like docker ,ngingx, implementing payment gateways and with highly recommended skills which increases productivity of a developer like public-speaking, leadership and teamwork with socializing also like to increase knowledge by solving different python based problems in different online platforms.

Views: 1,898

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on X (Opens in new window) X
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to email a link to a friend (Opens in new window) Email
  • Click to print (Opens in new window) Print

Like this:

Like Loading...

Related Posts

Total
0
Shares
Share 0
Tweet 0
Pin it 0

Leave a ReplyCancel reply

Subscribe to Website via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Recent Posts
  • Getting Started with AWS Step Functions: Orchestration Made Simple

    Getting Started with AWS Step Functions: Orchestration Made Simple

    2 months ago
  • React Hooks Guide: Top Tips for Optimizing Performance in Your React Applications

    React Hooks Guide: Top Tips for Optimizing Performance in Your React Applications

    2 years ago
  • Demystifying JavaScript Tree Shaking: Boosting Performance and Reducing Bundle Size

    Demystifying JavaScript Tree Shaking: Boosting Performance and Reducing Bundle Size

    2 years ago
  • Unlocking the Power of React Hooks: A Comprehensive Guide with Examples

    Unlocking the Power of React Hooks: A Comprehensive Guide with Examples

    2 years ago
  • Celebrating a Decade of Phenomenal Growth: Insights and Reflections on 10 Years of Software Engineering

    Celebrating a Decade of Phenomenal Growth: Insights and Reflections on 10 Years of Software Engineering

    2 years ago
  • Angular Custom Elements: Creating Reusable Components with Angular

    Angular Custom Elements: Creating Reusable Components with Angular

    3 years ago
  • Connect Firebase Realtime NoSQL Database with Angular App from Scratch

    Connect Firebase Realtime NoSQL Database with Angular App from Scratch

    5 years ago
  • How to Build an Inclusive Esports Community

    How to Build an Inclusive Esports Community

    5 years ago
  • Best Digital Icebreakers

    Best Digital Icebreakers

    5 years ago
  • Email alerts when a docker container stopped in AWS ECS CLUSTER

    Email alerts when a docker container stopped in AWS ECS CLUSTER

    5 years ago
Subscribe to Website via Email

Enter your email address to subscribe to this website and receive notifications of new posts by email.

Featured Posts
  • javascript 1
    Spread syntax (three dots) in JavaScript
    • March 21, 2018
  • Angular 2
    Angular 6 CRUD – Part 1: Project Setup, Routing, Service
    • May 9, 2018
  • javascript 3
    Local Storage and Session Storage
    • May 22, 2017
  • Angular 4
    Angular 4 Project Structure
    • June 18, 2017
  • AWS 5
    Email alerts when a docker container stopped in AWS ECS CLUSTER
    • July 24, 2020
Code4Developers
Learning is never ending process

Input your search keywords and press Enter.

%d