What's New in Python 3.11?

NeuralNine · Beginner ·📰 AI News & Updates ·3y ago

Key Takeaways

The video covers updates and changes in Python 3.11, including faster execution speed, fine-grained error messages, exception notes, TOML parser, type hinting, and string enums.

Full Transcript

what is going on guys welcome back in today's video we're going to learn what's new in Python 3.11 so let us get right into it [Music] all right so let's get started now if you want to follow along with this video if you want to play around with the latest python version instead of just listening to what's new you can go to python.org and download it from here by clicking on this button and you can also have multiple python installations so you can have if you go to my start menu you can see I have python 3.11 python 3.9 I also have some Anaconda environments as long as you know which version you're currently using this is not a problem but if you want to try out the new features you obviously have to use Python 3.11 also I would recommend you to go to the documentation and look at this what's new in Python entry here because here you get a detailed listing of all the changes all the updates all the improvements uh with every little detail all the minor changes and in this video today obviously I'm not going to cover all of it I'm going to limit myself to everything I think is useful interesting and valuable to you guys I want to keep this video short concise and simple so I'm not going to cover all the minor changes and all the stuff that I think most people will not use so I'm going to focus on the interesting stuff that you will probably use and you will probably benefit from and the first thing I want to mention here is something that we cannot really talk too much about because there's not much to show here I'm not going to do some fancy benchmarking because it has already been done but one of the biggest improvements of python 3.11 is the speed up so on average you get a 25 speed up compared to Python 3.11 and the ranges here between 10 and 60 percent as the documentation says so again I'm not going to show any fancy benchmarking here because you can see um everything that was changed and everything was done here and you can read about the speed Improvement here in the documentation but in general python 3.11 is now faster than python 3.10 which is a very good Trend to see because python is always considered to be a very slow language in terms of execution speed and every Improvement here is very beneficial to the language so this is one of the biggest improvements here now the first actual thing that I want to show in this video here is the improved error messages so what we can do here is I'm going to open up the idle just so we can do some coding so the 3.11 idle and I'm going to open up the file that I have prepared here I don't know if there's any code in here already so this is a function that I prepared um very simple we have some numbers we have divisors and we have a list comprehension so we just have a simple function that takes this list of numbers and divides it by this list of numbers and obviously we can see what the problem is here we're dividing by zero so this will cause a problem and with python 3.11 we now have more specific error messages so I have to open up the command line for this because it will not show in the python idle but if I navigate to this directory here and if I say python main.py with the default python that I have on my system you can see it just says um division by zero and it gives me that line which is the list comprehension but if I do it with the actual python 3.11 idle idle so here you can see now it's targeting 3.9 I can copy that and I can go to my Explorer here I can go to Python and you can also see I have python 3.11 so I can copy this I can paste it here I can say python.exit to Target this one and I can run main Qi as well and now you can see it's targeting this particular section here so it shows me exactly not just the line not just the segment it shows me exactly what part of this line is causing the problem and it's the division because the problem could also be you know if if the error is now not zero division error but some different era and I have a pretty complex line with functions and all that it could also be that I cannot iterate over the visors if if I get a different problem right so knowing that the era is particularly happening with this calculation here is very useful and this is a major feature of python 3.11 I think in a documentation you can also see the differences here so um we can see that it exactly shows us okay this is the problem here or here we have the problem so it targets the specific section and not just the line this is a very useful Improvement um also when we're talking about exceptions and errors already we can add custom exception notes so for example if I have something like try and I'm going to just divide by zero again so 10 divided by 0 I'm going to cause an exception I can say accept and then I can say zero division division era SE um what I can do now is I can add a note to the exception so if I just if I don't do any of that so if I just do this and I run this you can see that this just causes the zero division error and it says division by zero but I can also add a note for developers to know what's happening if the error situation is a little bit more complex I can go ahead this is wrong indentation I can go ahead and say e dot add underscore node to say are you sure you want to divide by zero for example just something to help the developer or the user to troubleshoot something that says okay look a common error in this particular segment if you're here chances are it's because of x y z in this case we're just asking are you sure you want to divide by zero we then just call a race at the end to raise to re-race this error and when I run this you can see Zero division error are you sure you want to divide by zero so this is also a nice feature and we can add multiple notes so I can also I'm going to now add the same note three times but you can see I can add multiple lines and all of them are going to be displayed so this is also a nice feature especially for developers maybe not so much for the user but especially for developers this is a very nice feature um and uh yeah so the next thing and this is also something interesting that maybe you have not thought about this because you haven't worked with those files but there's a new uh or a revenue modern configuration file type called Tomo which is used oftentimes instead of Json or yaml to provide settings or configuration so maybe I can open this up in the python Idol I don't actually think so can I know I mean probably I can let me just let me just uh get the code okay so I think the file should now have some content if I open it up again [Music] there you go so this is a configuration file in Tamil this basically means uh what was the name it was Tom's obvious minimal language and essentially this is a simple configuration file so here you can see we have a title value we have this service section where we have the IP the ports we have the player section here and all of this can be now read into core python or into python with a core python Library called tomolip so we can just say import Tomo lip and we can say with open settings.tomo in Reading bytes mode it's important that it's reading bytes and then as F we can just say data equals Tamil lib dot lot we're loading the file and then we can print the results you can see how easy it is to load Tamil files into python because you can see every section is translated into a dictionary so we have this server which has an IP address and a port those are now integers and strings inside of a dictionary which is linked to server because the whole thing is a dictionary so it's more or less converting this into Json if you want but you can see how easily you can just take a file like this which is a modern configuration type of file and you can just read it into Python and work with it and you can also use the load s the load s function here to load a string to load from the string so I think in this case I'm not sure about that I think we should be able to do it like that yeah we achieve the same result we just read the content in the normal reading mode and we take the string and we turn it into Tamil or we take the Tamil string and we turn it into python dictionary so that's also quite useful for those of you who work with this type of file uh the next thing is we have some updates on the typing so in Python we all know python is a dynamic type language but it allows for type hinting so we have tools like my Pi which check for the Integrity for the consistency of the typing so in Python what we can do those of you who are not familiar with that concept yet we can define a function my function and we can Define um the return values so I can say or or the the parameter value types so I can say here parameter or something and I can say that this parameter should be a string by doing just colon SDR and then I can say using this Arrow here that this function returns for example an integer and then I could just do return in parameter or something the interesting thing here is that I can do this I can Define this so I can just say my function then pass a string 100 for example and then I can print the result plus 20 to see that it actually worked I can run this parameter is not defined oh so you can see that actually works but the interesting thing about tie painting of course is that we don't have to um do what it says so I can also pass a floating Point number and it wouldn't be a problem for python because python is dynamically type I am not restricted to use just strings but for type hinting for documentation and for certain tools this means I have to use a string and I have to return integer if that's not the case it's inconsistent it's uh not the way it should be and we do type hinting to make our code more professional I have videos on that and now we have a couple of new things that we can do and the first thing I want to show you is the literal string so the literal string essentially means that we can pass a string to the function but it has to be a literal string not a constructed string and for that what we do is we say from typing import literal string and if I have some function where maybe this is very important so for example do some query or something and I have this query parameter I can say that I want this query to be a literal string um and this basically means let's just say we do something and then we pass or something it doesn't doesn't really matter what we do here but this type now means that I can only pass if I want to stay consistent python will allow me to do everything but if I want to stay consistent with the type hinting I would have to pass a string that is a literal string so if I say do some query and then select star from data or something that would be fine because that's a literal string um I mean there's no no value in really running this but uh what I cannot do or what I should not do if I want to stay consistent with the typing is using something like an F string where I say uh for example from I mean for the from it doesn't make sense if I have where ID equals and then you know some value some variable here variable equals 10 or something and then I say variable so this would not be a literal string now I can I can still do that without problems python will allow me to do that but it's not consistent with the literal string type hinting so that's a new thing we can do we can say okay the string that we passed needs to be a literal string it has to be just quotation marks without any formatting without any functions or anything like that um another thing that we have in the typing world is that we now have the self type which is quite useful when you have classes when I have for example the class my class and I have some our initialization method so the Constructor essentially and I give a name and I say self.name equals name for example and then I have some function uh let's say my my cool function or something and I get the self and I get some parameter and let's say the parameter is the string this function shall now return itself I mean not the function itself but the object itself so the self object is the instance of the class that we're currently working with and if I say for example let's say self.parameter uh or actually self.name equals parameter that's what I wanted to do parameter um and then I return self this worked before as well but if I want to say okay with type hinting this is actually returning itself what I had to do before is I had to work with a class so I had to provide the class and stuff like that now we can just do Arrow self to indicate that this function is returning the object itself and then we could do something like uh MC equals my class I can call it John and I can say new MC equals MC dot my cool function and then I can just print newmc.name uh what's the problem here parameter did I misspell it again parameter parameter what's the problem I don't get it oh of course I get it I didn't provide something here so let's say test there you go so this works but yeah this part is not actually the Improvement the Improvement or the or the update the new features that you can provide this self um typing this the self typing type or the self-type for the return value for the return type of the function uh to just indicate that it returns an object you don't have to work with a class name anymore so that's quite convenient as well and the last thing that I actually want to show for today and as I mentioned there are a couple more things that you can look into and I recommend you do so if you're very interested in a new version but the last thing I want to show today is that we can also use now string enums so up until this point what we had to do is we had to say from enum import enum and we created a class we called this my color for example and we said okay it inherits from enum and then I can do something like red equals if I want to use first of all I can use just numbers so red equals one green equals two and blue equals three so this was possible and then I could just say print my color dot Red Dot value for example I can run this and you can see it returns one this worked all the time and if we wanted to have string enums we had to type out the values so red equals red green equals green and blue equals blue and in this case it doesn't really matter too much but sometimes this might be a little bit tedious so what we can do instead with a new python version is we can use the Str enum combined with the auto function to automatically assign the string value so I can just say extend from Str enum and assign this automatically by just calling the auto function for all of those values and it's just going to take the name and turn it into a string and then when we run this you can see we get red as the value for red even though we didn't specify it so that's a Improvement that is again a minor Improvement but can be useful if you work with enums in a project you can now use this way of defining string enums so that's it for today's video I hope you enjoyed it and hope you learned something if so let me know by hitting the like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you in the next video and bye [Music]

Original Description

Today we cover the most interesting and useful updates and changes of the new Python version 3.11. Python 3.11 Documentation: https://docs.python.org/3/whatsnew/3.11.html ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm 🎵 Outro Music From: https://www.bensound.com/ Timestamps: (0:00) Intro (0:16) Faster Execution Speed (2:10) Fine-Grained Error Messages (4:30) Exception Notes (6:16) TOML Parser (8:44) Type Hinting (14:33) String Enums (16:11) Outro
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from NeuralNine · NeuralNine · 0 of 60

← Previous Next →
1 Visualizing Stock Data With Candlestick Charts in Python
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
2 Python Beginner Tutorial #1 - Installation and First Program
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
3 Python Beginner Tutorial #2 - Variables and Data Types
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
4 Python Beginner Tutorial #3 - Operators and User Input
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
5 Python Beginner Tutorial #4 - If Statements and Conditions
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
6 Python Beginner Tutorial #5 - Loops
Python Beginner Tutorial #5 - Loops
NeuralNine
7 Python Beginner Tutorial #6 - Sequences and Collections
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
8 Python Beginner Tutorial #7 - Functions
Python Beginner Tutorial #7 - Functions
NeuralNine
9 Python Beginner Tutorial #8 - Exception Handling
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
10 Python Beginner Tutorial #9 - File Operations
Python Beginner Tutorial #9 - File Operations
NeuralNine
11 Python Beginner Tutorial #10 - String Functions
Python Beginner Tutorial #10 - String Functions
NeuralNine
12 Python Intermediate Tutorial #1 - Classes and Objects
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
13 Python Intermediate Tutorial #2 - Inheritance
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
14 Python Intermediate Tutorial #3 - Multithreading
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
15 Python Intermediate Tutorial #4 - Synchronizing Threads
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
16 Python Intermediate Tutorial #5 - Events and Daemon Threads
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
17 Python Intermediate Tutorial #6 - Queues
Python Intermediate Tutorial #6 - Queues
NeuralNine
18 Python Intermediate Tutorial #7 - Sockets and Network Programming
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
19 Python Intermediate Tutorial #8 - Database Programming
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
20 Python Intermediate Tutorial #9 - Recursion
Python Intermediate Tutorial #9 - Recursion
NeuralNine
21 Python Intermediate Tutorial #10 - XML Processing
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
22 Python Intermediate Tutorial #11 - Logging
Python Intermediate Tutorial #11 - Logging
NeuralNine
23 Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
24 Python Data Science Tutorial #2 - NumPy Arrays
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
25 Python Data Science Tutorial #3 - Numpy Functions
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
26 Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
27 Python Data Science Tutorial #5 - Subplots and Multiple Windows
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
28 Python Data Science Tutorial #6 - Matplotlib Styling
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
29 Python Data Science Tutorial #7 - Bar Charts with Matplotlib
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
30 Python Data Science Tutorial #8 - Pie Charts with Matplotlib
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
31 Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
32 Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
33 Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
34 Python Data Science Tutorial #12 - Pandas Series
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
35 Python Data Science Tutorial #13 - Pandas Data Frames
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
36 Python Data Science Tutorial #14 - Pandas Statistics
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
37 Python Data Science Tutorial #15 - Pandas Sorting and Functions
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
38 Python Data Science Tutorial #16 - Pandas Merging Data Frames
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
39 Python Data Science Tutorial #17 - Pandas Queries
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
40 Python Machine Learning Tutorial #1 - What is Machine Learning?
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
41 Python Machine Learning Tutorial #2 - Linear Regression
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
42 Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
43 Python Machine Learning #4 - Support Vector Machines
Python Machine Learning #4 - Support Vector Machines
NeuralNine
44 Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
45 Python Machine Learning Tutorial #6 - K-Means Clustering
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
46 Python Machine Learning Tutorial #7 - Neural Networks
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
47 Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
48 Generating Poetic Texts with Recurrent Neural Networks in Python
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
49 Stock Portfolio Visualization with Matplotlib in Python
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
50 Analyzing Coronavirus with Python (COVID-19)
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
51 Making Text Images Readable Again with Python and OpenCV
Making Text Images Readable Again with Python and OpenCV
NeuralNine
52 Neural Networks Simply Explained (Theory)
Neural Networks Simply Explained (Theory)
NeuralNine
53 Motion Filtering with OpenCV in Python
Motion Filtering with OpenCV in Python
NeuralNine
54 Top 5 Programming Languages To Learn in 2020
Top 5 Programming Languages To Learn in 2020
NeuralNine
55 Simple TCP Chat Room in Python
Simple TCP Chat Room in Python
NeuralNine
56 Image Classification with Neural Networks in Python
Image Classification with Neural Networks in Python
NeuralNine
57 Edge Detection with OpenCV in Python
Edge Detection with OpenCV in Python
NeuralNine
58 S&P 500 Web Scraping with Python
S&P 500 Web Scraping with Python
NeuralNine
59 Simple Sentiment Text Analysis in Python
Simple Sentiment Text Analysis in Python
NeuralNine
60 Introduction - Algorithms & Data Structures #1
Introduction - Algorithms & Data Structures #1
NeuralNine

This video teaches the most interesting and useful updates and changes in Python 3.11, helping viewers stay current with the latest developments in the language.

Key Takeaways
  1. Check the Python 3.11 documentation for new features
  2. Understand the implications of faster execution speed
  3. Learn about fine-grained error messages and exception notes
  4. Explore the TOML parser and its use cases
  5. Understand type hinting and string enums
💡 Python 3.11 introduces several significant updates, including faster execution speed and improved error handling, making it an essential release for developers to understand.

Related Reads

📰
How Generative AI Is Transforming Modern Businesses (And Why It’s More Than Just ChatGPT)
Learn how generative AI is transforming modern businesses beyond ChatGPT, improving productivity and innovation
Medium · ChatGPT
📰
Apple opens its new Siri AI to everyone with the iOS 27 public beta
Apple releases iOS 27 public beta with revamped Siri AI for everyone to try
TechCrunch AI
📰
Google faces another AI training lawsuit from major publishers
Google faces lawsuit from major publishers for training AI on copyrighted works without permission, highlighting AI copyright concerns
TechCrunch AI
📰
Why RAM Prices Are Exploding: Inside the DRAM Shortage Fueling the AI Boom
RAM prices are surging due to the DRAM shortage caused by the AI boom, learn how this affects the tech industry and what it means for professionals
Medium · AI
Up next
PLATO Exoplanet Hunter Launch 2026 Searching for New Earths in a Warming World
Tech Folk Insights
Watch →