DEV Community

Cover image for What's coming in Python 3.8?
petercour
petercour

Posted on

What's coming in Python 3.8?

What will be added to Python 3.8? Quite some changes. Don't know Python, it's a good time to start

  • The walrus operator

The walrus operator will be addded (:=). That's because with a bit of imagination it looks like a walrus.

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)
        ...
Enter fullscreen mode Exit fullscreen mode

becomes:

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):
Enter fullscreen mode Exit fullscreen mode

  • Debug support for f-strings

What are f-strings you say? You can easily output stuff:

answer = 42
f'The answer is not {answer+1}'
f'The root of the answer is {math.sqrt(answer)}'
Enter fullscreen mode Exit fullscreen mode

A lot easier than adding + str(answer) and that kind of stuff.

  • Positional-only parameters
  • A movable pycache

and more things. Your old Python 3.x code will still work.

Related links:

Top comments (1)

Collapse
 
grozail profile image
Ilya

And, moreover, changes in multiprocessing :)
"multiprocessing can now use shared memory segments to avoid pickling costs between processes"