What's New in Python 3.9?
Skills:
AI Pair Programming80%
Key Takeaways
The video covers new features in Python 3.9, including dictionary merging operators, new string functions, type hinting, and GCD and LCM functions.
Full Transcript
[Music] what is going on guys welcome to this video today we're going to talk about the new features in python version 3.9 or at least some of the new features and i know this version is not uh was not released yesterday or two days ago it's been some time already uh but it's still the most recent version and a lot of you guys are not familiar with it and you don't know about the new features and for those of you who are interested in the new features of python 3.9 i'm making this video here so let us get right into it alright guys so in order to show you what's new in python 3.9 i'm opening up two idols here so two development environments first of all python 3.8 and then also python 3.9 and we're going to see what we can do in the left one or actually in the right one which we cannot do in the left one so the first thing we're going to talk about are dictionary merging operators and i've already made a video on that on dictionary merging in my python tips and tricks series um but in this video we're going to talk specifically about what is new and if you have a dictionary let's say we have dict 1 equals something i don't know we have a and a points to 10 or 8 has the value 10 and we have b and b has the value 50 or something this is the first dictionary then we have a second dictionary where we have something like um b as well but this time with a different value come on a different value 20 for example and then we also have c and c has another value of 30 or something so those are two dictionaries and what we did in uh 3.8 is if we wanted to merge it there are different possibilities there are different different ways to do it but one way was to just create a new dictionary by saying dig 3 for example equals and then those two star operators here the keyword arguments operators here to unpack the dictionary so we say dict 1 and then unpack dick 2 again now again also and if we do that we end up with dictionary three which is a merged dictionary where the second one overwrites everything that has to be overwritten in the first one and this is fine but one thing that we cannot do here is do the same thing with just an operator we cannot just say something like dict 3 equals dick 1 sum operator here and dig 2. and this is something that we can do in python 3.9 i'm going to copy those two lines here first one second one what we can do here is we can say dick three equals and now we can say dig one and now we can introduce a dictionary merging operator this is this one here just a uh basic straight line the or operator if you know it um and then dig two and this is the dictionary merging operator as you can see here if i go ahead and print dig three you can see that it's the same result but however here i cannot do this i cannot say dict one dig two this doesn't work we get an error because that is not uh supported here also what we can do is we can update a dictionary with an operator and in python 3.8 what we did for that is we just said dict1 updating by the way means taking the dictionary that already exists and just updating the values so you're still merging but you're not creating a third dictionary you're just using one of the dictionaries that you already have and overwrite the values in it so in this case dict 1 update dick 2. this would work as well as you can see and here we can do the same thing uh but with the merging operator combined with an assignment operator so in this case we can just say dict one merge equals dick two and we're getting the same result here now then we also have two new string functions which are used for removing the prefix and the suffix so let's say in python 3.8 uh we have a string here or actually let's first do it in 3.9 and then just show that it doesn't work in 3.8 let's say we have a string here like i don't know hello world and now we can go ahead and say remove prefix and the prefixes for example hello and as you can see it removes the prefix which is not something that we can do with other string functions because it's not replacing all occurrences of hello world for example if i have hello world hello and i say remove prefix hello it's not going to remove this hello here it's only going to remove the prefix so it's always removing the uh the first uh characters if they are the prefix right so if we have a bunch of strings that all start with i don't know message colon and we want to remove it we just say remove prefix message code and this is something that we can do in 3.9 we cannot do this in 3.8 so if i go ahead and say hello world here dot remove prefix hello it says no attribute remove prefix we don't have that uh and we have the same thing for the suffix so we can go ahead with the same string hello world hello dot remove suffix hello and it's going to do the opposite it's going to remove it in the end so if we have something like i don't know for example a bunch of strings here and they all end with backslash n or backslash t or i don't know something that we don't want to have here we can just go ahead and remove it with with the remove suffix method and this is also something that does not exist it does not exist in python 3.8 move suffix as you can see no attribute removes suffix all right so next we get to something that i've personally never used but it was already available in python 3.8 to some degree and it's called type hinting and type hinting means that you're hinting uh what type your variables return values parameters and so on are and yes python is dynamically typed so you're not necessarily limited to those types you can also add different types to the variables and lists and so on um but it's useful because there are certain plugins or tools that check if all these hints are satisfied so to say so if you're for example if you say i have an integer here and you assign a string python is going to allow you to do that but certain plugins maybe will say hey you're violating the type hints and it may be useful as a tool i've personally never used it so but however there's something new about that in python 3.9 because what you could do in python 3.8 is you could say something like i think how it's written is my variable colon then int equals 10 yes this is how you do the type hinting then you can also say something like give me a function my function has a parameter my param which is an integer and then we also have a return value that is an integer and the function returns 10 for example this is something that we can already do in python 3.8 but what we cannot do in python 3.8 is do the same thing for collections so we cannot say my list at least not that easily cannot say my list list integer equals one two three four five for example this does not work however this does work in python 3.9 so we can go ahead and say my list list of integers equals one two three four five as you can see this works and we're not going to see any effects here because i can still go ahead and say my list um i know my list 3 equals hello so it's not going to uh to forbid me that i can do this but if i'm using something that checks for the type hinting and if everything is satisfied and you know consistent i'm going to see that it's not because i'm adding a string to something that should be a list of integers then we also have something in the math module that is quite interesting if you go ahead and import math in python 3.8 you can go ahead and calculate the greatest common divisor so you can just go ahead and say math dot gcd greatest common divisor of two numbers so for example 10 and or actually let's take something like 15 and 25 and you can see it's 5 because both are divisible by 5 and there's no uh number higher than 5 greater than 5 that divides both numbers so this is the greatest common divisor however if i want to do this for multiple values i'm not able to do this so i cannot go ahead and say okay i want to know for 15 for 25 and for 125. it doesn't work expected two arguments got three however this is something that does work in python 3.9 because we can uh add as many values as we want to that function so we can go ahead and say import math math.gcd uh 15 25 125. as you can see we can also go ahead and break this thing by saying 17 which is a prime so we would get one um and we can add as many values as we want to that and not only to that function we can also use the lcm function i think it's called or actually i'm not sure if it even exists because that's the least common multiple i'm not sure if it even exists in python 3.8 no it doesn't even have that function in python 3.9 we have a new function as it seems which is math dot least common multiplier or multiple lcm and we can do the same thing for the least common multiple of for example five three and uh i don't know two and we can see it's 30 uh in this case uh or we can go ahead and say math lcm of seven two four or actually let's go with uh yeah let's go to four i don't care um and as you can see in this case it's 28. so this is a new function and this one now accepts uh a variable amount of parameters all right so that's it for this video i know that i didn't include all of the new features of python 3.9 but the purpose of this video is not to list all of them we have the documentation for that if i don't forget it i'm linking it down below in the description uh two things that should be mentioned maybe if you want to look into them is that decorators are now more flexible so if you're someone who uses decorators you might want to check out the python documentation about decorators and if you're someone who works a lot with date times you can also check out the native time zone functionality in the documentation other than that there are a lot of minor changes as well so if you're into python and if you want to know all the details go into the documentation and check it out um other than that thank you very much for watching see you in the next video and bye [Music] you
Original Description
Today we learn about some of the new key features introduced with Python 3.9. For a full list, check out the Python documentation down below.
Python 3.9 Documentation: https://docs.python.org/3/whatsnew/3.9.html
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
💻 The Algorithm Bible Book: https://www.neuralnine.com/books/
🐍 The Python 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
🎵 Outro Music From: https://www.bensound.com/
Timestamps:
(0:00) Introduction
(0:50) Dictionary Merging Operators
(3:49) New String Functions
(6:05) Type Hinting
(8:10) GCD and LCM Functions
(10:13) 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
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
Python Beginner Tutorial #5 - Loops
NeuralNine
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
Python Beginner Tutorial #7 - Functions
NeuralNine
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
Python Beginner Tutorial #9 - File Operations
NeuralNine
Python Beginner Tutorial #10 - String Functions
NeuralNine
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
Python Intermediate Tutorial #6 - Queues
NeuralNine
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
Python Intermediate Tutorial #9 - Recursion
NeuralNine
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
Python Intermediate Tutorial #11 - Logging
NeuralNine
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
Python Machine Learning #4 - Support Vector Machines
NeuralNine
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
Making Text Images Readable Again with Python and OpenCV
NeuralNine
Neural Networks Simply Explained (Theory)
NeuralNine
Motion Filtering with OpenCV in Python
NeuralNine
Top 5 Programming Languages To Learn in 2020
NeuralNine
Simple TCP Chat Room in Python
NeuralNine
Image Classification with Neural Networks in Python
NeuralNine
Edge Detection with OpenCV in Python
NeuralNine
S&P 500 Web Scraping with Python
NeuralNine
Simple Sentiment Text Analysis in Python
NeuralNine
Introduction - Algorithms & Data Structures #1
NeuralNine
More on: AI Pair Programming
View skill →Related Reads
📰
📰
📰
📰
I Ran 10 AI Coding Models Through Real Client Work — Here's the Bill
Dev.to · loyaldash
I finally counted my tokens before they hatched
Dev.to AI
How Claude Changed the Way I Build WordPress Products
Dev.to · Arvin Khezri
Onboarding Your AI Pair Programmer: From Spec-Driven Development to Kiro Powers
Dev.to · Istvan Verhas
🎓
Tutor Explanation
DeepCamp AI