avatarPranjal Saxena

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1748

Abstract

t for further usage.</p><figure id="2f70"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*6BxIiYVQaZMjr0Lqynr20Q.png"><figcaption>Screenshot by writer</figcaption></figure><p id="23da">It is not limited to two dictionaries, but we can use N number of dictionaries to combine.</p><figure id="5571"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*7F155cv9Eo0mQBL966xDJg.png"><figcaption>Screenshot by writer</figcaption></figure><p id="4419">Further, we can merge all the dictionaries using “|” and a loop. Here, in the below code, “<b><i>|=</i></b>” is also known as <b>an update operator</b> that performs the <b><i>merge in-place</i></b>.</p><figure id="8281"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*hL0ks0xExmJ0GX3d_5uwXA.png"><figcaption>Screenshot by writer</figcaption></figure><h1 id="e02e">Type Hinting</h1><p id="e1ae">This method is handy and timesaving functionality. It provides a hint for a programmer that a function requires a defined type argument. So, programmers don’t need to go through the entire code to check the argument’s usage and then accordingly pass the argument. It is more useful when the programmer is not aware of a function’s functionality but still needs to define the argument for the function call.</p><figure id="215d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*X6hMyQGolA6YFGjWEaDpJg.png"><figcaption>No type hinting (left), Python 3.9 <b>with </b>type hinting (right). Screenshot by writer</figcaption></figure><p id="2b9d">With the new type of hinting functionality, we can add “: int” to our parameter in the function definition, and our editor will immediately notice the error.</p><figure id="5083"><img src="https://cdn-i

Options

mages-1.readmedium.com/v2/resize:fit:800/0*pNaWUddAwYU6GZ3o.png"><figcaption>We can couple together different types to create more complex annotations. Screenshot by writer</figcaption></figure><h1 id="9ad2">String Methods</h1><p id="14c4">Here, we have two new functions that can be very handy sometimes. These functions are useful when we need to deal with the suffix and prefix in our data. When we have the data and in that data, checking for prefix and suffix plays a significant role, like in the banking sector, where we need to check for fraud or suspicious transactions continuously.</p><figure id="078e"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*OYLo_52vIfRfUOXnwlkItw.png"><figcaption>Remove Prefix, Screenshot by writer</figcaption></figure><figure id="049e"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*zCSYkdV3KNqhybNwoUXMOA.png"><figcaption>Remove Suffix, Screenshot by writer</figcaption></figure><h1 id="1482">Conclusion</h1><p id="fb2b">Cheers! We just checked some new Python 3.9 features that can be much handy sometimes. These features are a time saver and can help in faster and reliable coding experience. I like the “Type Hint” feature because I don’t need to go through the code or read the comment to know what goes inside a function call.</p><figure id="6fb1"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*eplgGxXMX8cRgfzw"><figcaption>Photo by <a href="https://unsplash.com/@wilstewart3?utm_source=medium&amp;utm_medium=referral">Wil Stewart</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p id="e450">Hope you like this informative article. Keep enjoying the journey.</p></article></body>

Python 3.9 New Features & How to Use Them

Python 3.9 new feature guide

Photo by Tyler Domingue on Unsplash

Python 3.9 is finally here, and it has some excellent features that can make the life of Python programmers easier. These features are moreover based on Strings, dictionary, and Type Hinting. Type Hinting might be a much newer concept in Python. But, it can help a lot in many cases. Also, it can save a lot much time for Python programmers. In this article, we will see these features with their demo.

Dictionary Unions

Dictionary plays a crucial role in Python. We can use a dictionary for different purposes. A dictionary can help build entire datasets in the data science field using a combination of lists and loops. Python 3.9 introduces two new features in the dictionary.

Merge Operator |: Now we can directly merge two dictionaries using the “|” merge operator. We will now try to play with the new merge operator. We have three dictionaries d0, d1, and d2. Lets, see how we can use the “|” operator here.

Screenshot by writer

Further, we can assign a newly formed dictionary to a variable using the “=” sign; then, we can use it for further usage.

Screenshot by writer

It is not limited to two dictionaries, but we can use N number of dictionaries to combine.

Screenshot by writer

Further, we can merge all the dictionaries using “|” and a loop. Here, in the below code, “|=” is also known as an update operator that performs the merge in-place.

Screenshot by writer

Type Hinting

This method is handy and timesaving functionality. It provides a hint for a programmer that a function requires a defined type argument. So, programmers don’t need to go through the entire code to check the argument’s usage and then accordingly pass the argument. It is more useful when the programmer is not aware of a function’s functionality but still needs to define the argument for the function call.

No type hinting (left), Python 3.9 with type hinting (right). Screenshot by writer

With the new type of hinting functionality, we can add “: int” to our parameter in the function definition, and our editor will immediately notice the error.

We can couple together different types to create more complex annotations. Screenshot by writer

String Methods

Here, we have two new functions that can be very handy sometimes. These functions are useful when we need to deal with the suffix and prefix in our data. When we have the data and in that data, checking for prefix and suffix plays a significant role, like in the banking sector, where we need to check for fraud or suspicious transactions continuously.

Remove Prefix, Screenshot by writer
Remove Suffix, Screenshot by writer

Conclusion

Cheers! We just checked some new Python 3.9 features that can be much handy sometimes. These features are a time saver and can help in faster and reliable coding experience. I like the “Type Hint” feature because I don’t need to go through the code or read the comment to know what goes inside a function call.

Photo by Wil Stewart on Unsplash

Hope you like this informative article. Keep enjoying the journey.

Python
Data Science
Machine Learning
New Features
Trends
Recommended from ReadMedium