Python is an open-source programming language. What makes Python open-source is that it is constantly been upgraded by the Python community. The community comes up with exciting new upgrades and features in Python every year.
This is 2022 and this is the year of Python’s 3.11 version.
Python 3.11 has been officially launched on October 24.
New features and upgrades in Python 3.11
1. Python 3.11 is faster than Python 3.10
The community has well put in docs that Python 3.11 can be up to 60% faster than Python 3.10. Also, the benchmark suite runs up to 25% faster than in 3.10. This can be profitable to Python programmers and data scientists.
To run this benchmark test to compare the speeds of Python 3.10 and Python 3.11, you will need a docker installation on the system.
2. Exception Notes
Python 3.11 offers a new function called add_notes() to make the exceptions as expressive as possible. Any custom messages can be passed so that they will be displayed if any error will be raised.
Look at this code snippet:
On running, you can see your custom note has been displayed on the terminal
This feature is pretty useful in dealing with errors.
Talking about the error part, the next major upgrade Python 3.11 came with is explained in the next part.
3. More Expressive Error Messages
Python 3.11 has a new upgrade with the display of error messages. Previously, the interpreter would throw an error mentioning the line number and error description, but with this version, the ~ and ^ characters are added to specify where the error actually might be.
Take a previous example, Division by zero error.
The characters ~ and ^ stating the actual part of the error.
This feature makes debugging a lot easier.
4. New Modules in Python 3.11
a. TOML Support
The human-friendly and computer-friendly Tom’s Obvious Minimal Language has now been included in Python’s standard library tomllib. TOML provides metadata for projects and packages.
b. wsgiref.types
This module provides utilities for static type checking.
5. Upgradations to Standard Libraries
Most of the common and stand libraries of Python gone improved with Python 3.11.
- math library has been updated with functions for computing cube root and power of 2.
- datetime library contains functions for iso formats
- A new module fractions has also been added that let user can create fractions from strings.
- Libraries such as typing, os, functools, enum, SQLite, etc are upgraded with new features.
6. typing : self
In previous versions of Python, the function returning self-objects was a lot more confusing and almost impossible. But typing library in Python 3.11 includes a self that lets you return the instances of a class.
7. Typedict: Required and NotRequired
All the fields in the typedict used to be compulsory. But Python 3.11 introduces Required and NotRequired, which can mark if the item is mandatory or not.
class Movie(TypedDict):
title: str
year: NotRequired[int]
The title is a required parameter whereas the year is not.
Considering the examples,
m1: Movie = {"title": "Black Panther", "year": 2018}
m2: Movie = {"title": "Star Wars"}
m3: Movie = {"year": 2022}
object m1 and m2 will work fine but object m3 will throw an error.
Conclusion
These were some major upgrades in Python 3.11.
It is recommended to update Python with the latest version because 3.11 is faster, more expressive, and has static typing support, and TOML support.
For more detailed information about Python 3.11, visit here.
Installation of Python 3.11:
Python 3.11 is available to install on the official websites.
Check it out here.
Thank-you.
Also Read:
- Free Python Certification course from Alison: Good for Resume
- Download 1000+ Projects, All B.Tech & Programming Notes, Job, Resume & Interview Guide, and More – Get Your Ultimate Programming Bundle!
- Top 5 Websites to Learn Programming in 2024
- Python Internship for college students and freshers: Apply Here
- New secrets to Earn money with Python in 2024
- Connect with HR Directly – Job Hack
- Google offering free Python course: Enroll Today
- Google Internship 2024
- TCS Launched Free Certification Course with Industry Recognized Value
- What is web development for beginners?
- Python | Check Armstrong Number using for loop
- Python | Factorial of a number using for loop
- Microsoft Giving Free Machine Learning Course: Enroll Now
- Accenture Giving Free Developer Certificate in 2023
- Amazon Summer Internship 2023
- Amazon Giving Free Machine Learning Course with Certificate: Enroll Now
- Google Summer Internship 2023
- 5 Secret ChatGPT skills to make money
- Free Google Certification Courses
- 5 AI tools for coders better than ChatGPT
- New secrets to Earn money with Python in 2023
- How to utilize ChatGPT to improve your coding skills?
- Create your own ChatGPT with Python
- Bakery Management System in Python | Class 12 Project
- SQLite | CRUD Operations in Python
- Event Management System Project in Python
- Ticket Booking and Management in Python
- Radha Krishna using Python Turtle
- Hostel Management System Project in Python
- Sales Management System Project in Python