Cool New Features in Python 3.8

Watch Now This instructional exercise has a related video course made by the Real Python group. Watch it together with the written tutorial to extend your understanding: Cool New Features in Python 3.8

The newest version of Python is released! Python 3.8 has been accessible in beta versions since the summer, but on October 14th, 2019 the first official version is prepared. Now, we can all start playing with the new features and advantage from the recent improvements.


What does Python 3.8 bring to the table? The documentation gives a good overview of the new highlights. In any case, this article will go more in depth on some of the greatest changes, and give you how you can take advantage of Python 3.8.

In this article, you’ll learn about:



Using assignment expressions to simplify some code constructs

Enforcing positional-only arguments in your own functions

Specifying more precise type hints

Using f-strings for simpler debugging


How to Get Started With Python | Starting with Python


With a few exceptions, Python 3.8 contains many small improvements over the earlier versions. Towards the end of the article, you’ll see many of these less attention-grabbing changes, as well as a discussion about some of the optimizations that make Python 3.8 faster than its predecessors. Finally, you’ll get some advice about upgrading to the new version.

Free Bonus: Click here to get access to a section from Python Tricks: The Book that gives you Python's best practices with simple examples you can apply immediately to write more beautiful + Pythonic code.

Free Bonus: Click here to gain admittance to a section from Python Tricks: The Book that gives you Python's prescribed procedures with straightforward models you can apply immediately to compose




The Walrus in the Room: Assignment Expressions

The biggest change in Python 3.8 is the introduction of assignment expressions. They are written using a new notation (:=). This operator is often called the walrus operator as it resembles the eyes and tusks of a walrus on its side.

Assignment expressions allow you to assign and return a value in the same expression. For example, if you want to assign to a variable and print its value, then you typically do something like this:

>>> walrus = False

>>> print(walrus)

False

In Python 3.8, you’re allowed to join these two statements into one, utilizing the walrus administrator:

>>> print(walrus := True)

True

The task expression enables you to assign True to walrus, and quickly print the value.

not

One pattern that shows some of the strengths of the walrus operator is while loops where you need to initialize and update a variable. For example, the following code asks the user for input until they type quit:

inputs = list()

current = input("Write something: ")

while current != "quit":

inputs.append(current)

current = input("Write something: ")


read more at- Python training in Chandigarh


before

inputs = list()

while True:

current = input("Write something: ")

if current == "quit":

break

inputs.append(current)


this loop further:

inputs = list()

while (current := input("Write something: ")) != "quit":

inputs.append(current)



This moves the test back to the while line, where it should be. However, there are now several things happening at that line, so it takes a bit more effort to read it properly. Use your best judgement about when the walrus operator helps make your code more readable.

PEP 572 describes all the details of assignment expressions, including some of the rationale for introducing them into the language, as well as several examples of how the walrus operator can be used.


Python training in Chandigarh

CBitss Provides Best Python Training in Chandigarh. if you are looking Best Training institute In Chandigarh Than Join CBitss... Website - http://cbitss.in/python-training-in-chandigarh/
Follow
4.7 Star App Store Review!
Cpl.dev***uke
The Communities are great you rarely see anyone get in to an argument :)
king***ing
Love Love LOVE
Download

Select Collections