New Features in Python 3.10
Skills:
LLM Foundations85%
Key Takeaways
Python 3.10 introduces new features such as structural pattern matching, a new typing Union operator, and parenthesized context managers, which improve the language's syntax and error handling capabilities.
Full Transcript
hi and welcome to this video we're going to explore what is new in python 3.10 there are a few different things i want to cover there we have some more additions to typing which i think are pretty cool the parenthesis context manager which is kind of an interesting update because it's not really an update so we'll get into that pretty soon we have structural pattern matching which i've covered before we're just going to run through that really quickly in this video and then there is also a load of new error messages which are pretty interesting actually some there's some really good ones in there so so we'll go through all of those new features in python 3.10 okay so in the last few iterations of python there's been a steady improvement of the python's type hinting or type annotations capabilities and with python 3.10 we are seeing more of that again now there's a few changes or a few updates and features with the typing in python 3.10 but i think the most interesting one is the addition of a new operator so this is what we used to have to do in python 3.9 and before so in here i'm just defining really simple function that adds two integers or floats together now if we want to define x and y as being potentially an integer data type or a float data type then we would have to use this union operator which would import from typing up here now with python 3.10 we don't have to do that anymore it's much simpler all we do is include the pipe character here which is our new union operator which obviously it looks a lot cleaner so that's the main new feature with type annotations in 3.10 so let's move on to the new parenthesis context manager okay so what we're talking about when we talk about context managers is it's exactly what you can see on the screen now so we have this is the most common example of the context manager in python and this is just how we read in our files so we have with so this is setting up our context and here we are assigning this stream here as f okay and then within this indented area we can read f but outside of it we can't so we couldn't write something like text equals f dot read because in this case f just doesn't exist outside of that context so that's what we mean by context manager now if we wanted to open multiple context managers within the same area we could write something like this so we'd have with open then we have another open afterwards and then we'll be able to access both of those within this indented area the only problem is that we would have to keep all of this on the same line due to limitations with python's previous password now the pastor got updated in python 3.9 which is why i say this is kind of not really a new update but it is a new update so before then we had to keep everything on a single line and we could get around that a little bit by adding the line continuation character and this would work as well but the problem with this is that it's not technically pythonic which i mean for most people it doesn't really matter but now what has been added thanks to the new python parser which introduced in 3.9 is we can include parenthesized context managers so we can add these inside brackets and that will now work and this is officially a new feature for python 3.10 but we can actually switch back to python 3.9 and if i run this again we see that it still works so that's kind of weird right now the reason for that is that the parser the new parser introducing at 3.9 allows this syntax to work but it was not added as a genuine new feature until python 3.10 now why that has been done i really can't tell you because i don't understand but that is just how it is now if we if we take this back one version further to 3.8 we see that we do actually get the invalid syntax so this is a a new feature but it's also not a new feature so it's a yeah that's a strange one now the next one which i think is probably the most hyped new feature of 3.10 and with good reason it is very cool is the structural pattern matching now we can write this statement here and this is just a simple example we're going to move on to you know a real example in a moment this is an if else statement and we're just checking this code we can run that without problem and some new syntax has been added in python 3.10 and that is the match case statement so this is the equivalent of what we did up here but using the new match case syntax which okay that's you know it's interesting it's cool but it doesn't doesn't really bring us anything new we could just do that with a if else statement before so that's not particularly interesting but what is interesting is the structural pattern matching part of this new syntax which allows us to do this match case comparison but rather than specifying whether that http code is an exact match to whatever values are in those case statements we can check the structure of a object and check if it matches a pattern which you pass through the case statement which is very very cool now let's see how that works so if i remove these two i'm going to define a dictionary here so dictionary a and dictionary b now these two both contain similar information but they're in a different structure so that means that we would have to access both of these using different paths now what we can do is create a pattern that matches both of these and add them both within a match case statement and we can use that to check which pattern we have and perform a different operation on each one so to do that first so this is our our code we're going through in a loop through dictionary a dictionary b and i've just added this string called test that shouldn't match to anything because it's just a string okay so we're looping through each of those and we're going to test the match case on each one so first so we're matching here and then we have our case and then here is our pattern so this is the pattern we want to match now if we compare that pattern we'll see that we have id and meta id and meta and inside meta we have another dictionary which contains source and location and here we have solution location as well now this doesn't need to be perfect match by the way we could this would also match if i got rid of location like that and obviously would have to go loc here as well so it doesn't have to be a perfect match just as long as whatever you have entered does fit into the structure that we are comparing against now that's the first one but that will not match to this because we don't have the meta key and the meta does not contain no dictionary okay and in dict b but it does match this one which is id source and location same as this one here so that will match and then here we have our catch-all statement so this is like our else statement and this will just catch any items that do not match either of those cases eg our test at the end there so let's run that and see what it prints okay so we see that we get the first one so it manages to extract ident source and loc and print those all out and then for the second one it does the same even though they're a different structure because it matches to this different case and then here we have our catch-all number print out no match so this i think easily is the coolest feature in in 3.10 and i've already found it useful for processing data in a similar way to what i'm showing here so it's in my opinion super cool and something to be excited for so let's move on to our final new feature which are the new and improved error messages okay so let's move on to the new error messages in 3.10 so they've done quite a few new messages here that are just a lot easier to understand so for example if we take this unclosed dictionary in 3.9 we get this unexpected eof while passing eof means end of file so this basically is telling us that the parser has gone all the way to the end of the file and it hasn't found the closing brackets of our dictionary and okay fair enough once you've been using python for a while you know what it means that's fine but this isn't particularly clear especially if you're new to python i mean i'm certain that the first time i got this error and i'm certain that almost everyone the first time i got this error will have had to google what this means now in python 3.10 now it's really simple it's telling us that our dictionary was never closed which is much better now in the same sort of area we also have unclosed strings where we get this eol which is end of line and that means the same thing again saying we've got to the end of the line and your string isn't closed now in python 3.10 rather than that we get this unterminated string literally and that's just so much easier to understand another one is assignment versus comparisons so obviously here we should have a double equal sign because we're comparing we're not making two equal to three so if we run that we just get invalid syntax now for us obviously we we know what's going on there but maybe if you're new to language it might not be so clear so now what we get is cannot assign to a literal here maybe you meant double equal sign not a single equal sign so a lot clearer again now another error that i think is pretty interesting although i can't seem to get working at the moment is where we enter a incorrect attribute name so usually we get this attribute error and that is essentially what we will also get over here in python 3.10 but as well as this although we don't see here we should also get a suggested attribute name based on whichever attribute has the closest match now i'm not sure why it doesn't work here but if we take a look here on the actual what's new python page we can see that this should give us a recommendation of do you mean named tuple which i think is is pretty cool and we should also get the same with named errors as well so if we have this new variable on the left we'll see that we get its name error new vr is not fine because we have typo it's fine and then in python 3.10 what we should find is that this will also recommend hey this isn't quite right maybe you meant new var okay and we can see this uh in this example here on the what's new page so overall i think those new error messages are definitely a lot clearer and they're probably going to help a lot of people so that's really good to see okay so that's everything for this video i hope it's been useful and i'll see you in the next one
Original Description
The Python 3.10 release has several new features like structural pattern matching, a new typing Union operator, and parenthesized context managers!
Python 3.10 has now been released, here we test all of the best new features introduced.
We'll cover some of the most interesting additions to Python - structural pattern matching, parenthesized context managers, more typing, and the new and improved error messages.
Download the latest release:
https://www.python.org/downloads/release/python-3100/
🤖 70% Discount on the NLP With Transformers in Python course:
https://bit.ly/3DFvvY5
📙 Medium article:
https://towardsdatascience.com/whats-new-in-python-3-10-a757c6c69342
🎉 Sign-up For New Articles Every Week on Medium!
https://medium.com/@jamescalam/membership
📖 If membership is too expensive - here's a free link:
https://towardsdatascience.com/whats-new-in-python-3-10-a757c6c69342?sk=648ae12c1025a83affba4eecec0d46c6
👾 Discord
https://discord.gg/c5QtDB9RAP
🕹️ Free AI-Powered Code Refactoring with Sourcery:
https://sourcery.ai/?utm_source=YouTub&utm_campaign=JBriggs&utm_medium=aff
00:00 Intro
00:45 Type Annotations in Python
01:10 Typing Union Operator
02:07 Parenthesized Context Managers
05:07 Structural Pattern Matching
09:31 Better Error Messages
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from James Briggs · James Briggs · 40 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
▶
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Stoic Philosophy Text Generation with TensorFlow
James Briggs
How to Build TensorFlow Pipelines with tf.data.Dataset
James Briggs
Every New Feature in Python 3.10.0a2
James Briggs
How-to Build a Transformer for Language Classification in TensorFlow
James Briggs
How-to use the Kaggle API in Python
James Briggs
Language Generation with OpenAI's GPT-2 in Python
James Briggs
Text Summarization with Google AI's T5 in Python
James Briggs
How-to do Sentiment Analysis with Flair in Python
James Briggs
Python Environment Setup for Machine Learning
James Briggs
Sequential Model - TensorFlow Essentials #1
James Briggs
Functional API - TensorFlow Essentials #2
James Briggs
Training Parameters - TensorFlow Essentials #3
James Briggs
Input Data Pipelines - TensorFlow Essentials #4
James Briggs
6 of Python's Newest and Best Features (3.7-3.9)
James Briggs
Novice to Advanced RegEx in Less-than 30 Minutes + Python
James Briggs
Building a PlotLy $GME Chart in Python
James Briggs
How-to Use The Reddit API in Python
James Briggs
How to Build Custom Q&A Transformer Models in Python
James Briggs
How to Build Q&A Models in Python (Transformers)
James Briggs
How-to Decode Outputs From NLP Models (Python)
James Briggs
Identify Stocks on Reddit with SpaCy (NER in Python)
James Briggs
Sentiment Analysis on ANY Length of Text With Transformers (Python)
James Briggs
Unicode Normalization for NLP in Python
James Briggs
The NEW Match-Case Statement in Python 3.10
James Briggs
Multi-Class Language Classification With BERT in TensorFlow
James Briggs
How to Build Python Packages for Pip
James Briggs
How-to Structure a Q&A ML App
James Briggs
How to Index Q&A Data With Haystack and Elasticsearch
James Briggs
Q&A Document Retrieval With DPR
James Briggs
How to Use Type Annotations in Python
James Briggs
Extractive Q&A With Haystack and FastAPI in Python
James Briggs
Sentence Similarity With Sentence-Transformers in Python
James Briggs
Sentence Similarity With Transformers and PyTorch (Python)
James Briggs
NER With Transformers and spaCy (Python)
James Briggs
Training BERT #1 - Masked-Language Modeling (MLM)
James Briggs
Training BERT #2 - Train With Masked-Language Modeling (MLM)
James Briggs
Training BERT #3 - Next Sentence Prediction (NSP)
James Briggs
Training BERT #4 - Train With Next Sentence Prediction (NSP)
James Briggs
FREE 11 Hour NLP Transformers Course (Next 3 Days Only)
James Briggs
New Features in Python 3.10
James Briggs
Training BERT #5 - Training With BertForPretraining
James Briggs
How-to Use HuggingFace's Datasets - Transformers From Scratch #1
James Briggs
Build a Custom Transformer Tokenizer - Transformers From Scratch #2
James Briggs
3 Traditional Methods for Similarity Search (Jaccard, w-shingling, Levenshtein)
James Briggs
3 Vector-based Methods for Similarity Search (TF-IDF, BM25, SBERT)
James Briggs
Building MLM Training Input Pipeline - Transformers From Scratch #3
James Briggs
Training and Testing an Italian BERT - Transformers From Scratch #4
James Briggs
Faiss - Introduction to Similarity Search
James Briggs
Angular App Setup With Material - Stoic Q&A #5
James Briggs
Why are there so many Tokenization methods in HF Transformers?
James Briggs
Choosing Indexes for Similarity Search (Faiss in Python)
James Briggs
Locality Sensitive Hashing (LSH) for Search with Shingling + MinHashing (Python)
James Briggs
How LSH Random Projection works in search (+Python)
James Briggs
IndexLSH for Fast Similarity Search in Faiss
James Briggs
Faiss - Vector Compression with PQ and IVFPQ (in Python)
James Briggs
Product Quantization for Vector Similarity Search (+ Python)
James Briggs
How to Build a Bert WordPiece Tokenizer in Python and HuggingFace
James Briggs
Metadata Filtering for Vector Search + Latest Filter Tech
James Briggs
Build NLP Pipelines with HuggingFace Datasets
James Briggs
Composite Indexes and the Faiss Index Factory
James Briggs
More on: LLM Foundations
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Claude AI vs ChatGPT: Which One Is Actually Better in 2026?
Medium · AI
Claude AI vs ChatGPT: Which One Is Actually Better in 2026?
Medium · Programming
IntelliBooks: Classic RAG vs Graph RAG vs Agentic RAG – Choosing the Right AI Retrieval Architecture for Enterprise AI
Dev.to AI
Fluid, natural voice translation with Gemini 3.5 Live Translate
Dev.to AI
Chapters (6)
Intro
0:45
Type Annotations in Python
1:10
Typing Union Operator
2:07
Parenthesized Context Managers
5:07
Structural Pattern Matching
9:31
Better Error Messages
🎓
Tutor Explanation
DeepCamp AI