Welcoming Python 3.10 | What’s New in Python 3.10

Installation

To Check the current version of python in Linux. Write

python3 --version

I currently Have python 3.8.5, So lets upgrade it to python 3.10.

Step 1 Download the Release from Python Official Website

https://www.python.org/downloads/release/python-3100a6/

During the time of writing article the latest release available is Python 3.10.0a6

Download the Tarball Gzipped Source Relase

Step 2 Extract the Release and Install

First extract the tar in a folder using

tar -xvf ./file-name-release

Once Extracted, move into the folder and configure the script using

./configure

Once the configuration is checked, move to the next step.

I will suggest to install this pre release as a alternate installation instead of installing it as primary Python Version

sudo make altinstall

This will start building the latest python release,

And Done now the system should have the latest python release installed. You can check it by

python3.10

New and Updates in Python 3.10

First of all, as this article is based on a pre release, so don’t use the python 3.10 as your primary driver.

So once all this is done, lets see what is coming in python 3.10

1. No More Unexpected EOF Syntax Error with Unclosed Braces

Yep , We have all been there, the famous Syntax Error Unexpected EOF Error while parsing a python dictionary when a brace is missed.

Example: Lets say a python file contains a code piece something like

a = {"Key1":1, "key2":2

On running the above file the output right now looks something like

Lets run the same file with python 3.10, Now the parser gives a better error message correctly indicating the point of error.

Not just this, lets take a bit complex nested dictionary.

a = {"Key1":1, "key2":2, "key3":[{"key3.1":5]}

The error gives exact order of the brace missing

2. The Switch Case is finally in Python Now

We all are familiar with C / C++ Match Case Syntax where you create a match variable and different possible values in switch. So it is now in Python with much complex possibilities.

For Example :

def check(point):
    match point:
        case (0, 0):
            print(f"{point=} Origin")
        case (0, y):
            print(f"{point=} Y={y}")
        case (x, 0):
            print(f"{point=} X={x}")
        case (x, y):
            print(f"{point=} X={x}, Y={y}")
        case _:
            raise ValueError("Not a point")

point = (0,2)
check(point)

The Output:

It also works with Enums:

Code:

from enum import Enum
class Color(Enum):
    RED = 0
    GREEN = 1
    BLUE = 2

color = Color(2)

match color:
    case Color.RED:
        print("I see red!")
    case Color.GREEN:
        print("Grass is green")
    case Color.BLUE:
        print("I'm feeling the blues :(")

Output:


REVIEWS

If You find it interesting!! we would really like to hear from you.

Ping us at Instagram/@the.blur.code

IF YOU WANT ARTICLES ON ANY TOPICS DM US ON INSTA.

Thanks for reading!! 

Happy Coding

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
Hey, wait!

Before you dive into the exciting Article, wanna join our newsletter list, We promise we will not spam