Python 3.8 is the latest version of the popular language for everything from scripting and automation to machine learning and web development. Now available in an official beta release, Python 3.8 brings a number of slick syntax changes, memory sharing, more efficient serialization and deserialization, revamped dictionaries, and much more.
Naturally, Python 3.8 ushers in all manner of performance improvements as well. The overall result is a faster, more concise, more consistent, and more modern Python. Here’s what’s new and most significant in Python 3.8.
The single most visible change in Python 3.8 is assignment expressions, which use what is known as the walrus operator (
:= ). Assignment expressions allow a value to be assigned to a variable, even a variable that doesn’t exist yet, in the context of an expression rather than as a stand-alone statement.
while (line := file.readline()) != "end": print(chunk)
In this example the variable
line is created if it doesn’t exist, then assigned the value from
line is checked to see if it equates to
"end". If not, the next line is read, stored in
line, tested, and so on.