What's New in Python 3.9?

NeuralNine · Beginner ·💻 AI-Assisted Coding ·5y ago

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 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 new key features introduced in Python 3.9, including dictionary merging operators, new string functions, type hinting, and GCD and LCM functions. It provides an overview of what's new in Python 3.9 and how to use these features in programming. The video is suitable for beginners who want to learn about the latest updates in Python.

Key Takeaways
  1. Learn about dictionary merging operators
  2. Understand new string functions
  3. Use type hinting
  4. Apply GCD and LCM functions
  5. Practice using these features in Python 3.9
💡 Python 3.9 introduces several new features that can improve programming efficiency and effectiveness.

Related Reads

📰
I Ran 10 AI Coding Models Through Real Client Work — Here's the Bill
Discover the costs of using AI coding models for real client work and learn how to apply this knowledge to your own projects
Dev.to · loyaldash
📰
I finally counted my tokens before they hatched
Learn how to utilize AI tools like git-lrc and Claude to enhance coding productivity and get feedback on your code
Dev.to AI
📰
How Claude Changed the Way I Build WordPress Products
Learn how AI-powered tools like Claude can revolutionize WordPress product development and improve workflow efficiency
Dev.to · Arvin Khezri
📰
Onboarding Your AI Pair Programmer: From Spec-Driven Development to Kiro Powers
Learn how to onboard an AI pair programmer, from spec-driven development to Kiro Powers, to boost productivity and efficiency in software development
Dev.to · Istvan Verhas
Up next
CodeAI at #ISTELive and their free lessons and learning space
Cool Cat Teacher
Watch →