Python 3.8 release

The most interesting innovations:

  • Assignment expression:

    The new := operator allows you to assign values ​​to variables within expressions. For example:
    if (n := len(a)) > 10:
    print(f"List is too long ({n} elements, expected <= 10)")

  • Positional-only arguments:

    Now you can specify which function parameters can be passed through the named argument syntax and which cannot. Example:
    def f(a, b, /, c, d, *, e, f):
    print(a, b, c, d, e, f)

    f(10, 20, 30, d=40, e=50, f=60) # OK
    f(10, b=20, c=30, d=40, e=50, f=60) # error, `b` cannot be a named argument
    f(10, 20, 30, 40, 50, f=60) # error, `e` must be a named argument

    This change gives developers a way to protect users of their APIs from changing the name of function arguments.

  • f-string = support for self-documenting expressions and debugging:

    Added sugar to simplify debug/logging messages.
    n = 42
    print(f'Hello world {n=}.')
    # will print "Hello world n=42."

  • Fixed the continue keyword in the finally block (it didn't work before).

Other:

  • You can explicitly specify the path to the bytecode cache instead of the default __pycache__.
  • Debug and Release builds use the same ABI.

Source: linux.org.ru

Add a comment