Fundamentals 9 min read

What’s New in Python 3.8? Key Features and Improvements Explained

Python 3.8, now in beta 2, introduces several notable enhancements—including the assignment expression (walrus operator), improved f‑string debugging, keyword‑only arguments enforcement, relocatable __pycache__, faster C‑extension calls, and various module updates—while targeting an official release by October 2019.

21CTO
21CTO
21CTO
What’s New in Python 3.8? Key Features and Improvements Explained

Python is a widely praised dynamic language whose frequent updates affect the development community. The Python Software Foundation has released beta 2 of Python 3.8, completing the addition of new features and aiming for a final release in October 2019.

Source: Machine Heart (ID: almosthuman2014) – compiled by contributors.

Python 3.8 continues the language’s strong presence in scripting, data analysis, and web back‑end development. After Python 3.7’s release in June 2018, the development and testing of 3.8 progressed quickly, with beta 1 released in early June and beta 2 a month later.

01 New Syntax

1. Assignment expression (:=)

The new walrus operator allows assignment within an expression, reducing code duplication.

m = re.match(p1, line)
if m:
    return m.group(1)
else:
    m = re.match(p2, line)
    if m:
        return m.group(2)
    else:
        m = re.match(p3, line)
        ...

Using the assignment expression, the same logic becomes more concise:

if m := re.match(p1, line):
    return m.group(1)
elif m := re.match(p2, line):
    return m.group(2)
elif m := re.match(p3, line):
    ...

2. f‑string debugging support

Python 3.8 enhances f‑strings so they can display both the expression and its value, aiding debugging.

print(f'foo={foo} bar={bar}')

Now the same output can be obtained more clearly:

print(f'{foo=} {bar=}')

Additional format specifiers such as !s and !f control the representation:

now = datetime.datetime.now()
print(f'{now= } {now=!s}')
print(f'{math.pi=!f:.2f}')

Spacing inside the braces also affects the printed spacing:

a = 37
print(f'{a = }, {a = }')

3. Positional‑only parameters (no keyword)

Python 3.8 introduces the / marker in function definitions to enforce positional‑only arguments.

def pow(x, y, z=None, /):
    r = x**y
    if z is not None:
        r %= z
    return r

Mixing positional‑only and keyword‑only parameters is also possible:

def fun(a, b, /, c, d, *, e, f):
    ...

fun(1, 2, 3, 4, e=5, f=6)          # legal
fun(1, 2, 3, d=4, e=5, f=6)       # legal
fun(a=1, b=2, c=3, d=4, e=5, f=6)  # illegal

02 Other Features

1. Relocatable __pycache__

The __pycache__ directory now stores version‑specific .pyc files (e.g., module.cpython-37.pyc), supporting multiple Python implementations such as PyPy.

2. Additional improvements

Python 3.8 adds an experimental faster call protocol for C extensions, cleans up interpreter initialization for easier embedding, and updates many standard‑library modules including os.path, shutil, math, and ssl.

03 When will Python 3.8 be released?

The exact release date is still under discussion, but the Python community expects the final version no later than October 2019, ahead of Python 3.9’s planned release around June 2020.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonNew Featuresassignment expressionPython 3.8f-stringPositional‑only Parameters
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.