GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing iscinumpy.dev — Python 3.8 Python 3.8 is out, with new features and changes. The themes for this release have been performance, ABI/internals, and static typing, along with a smattering of new syntax. Given the recent community statement on Python support, we should be staying up to date with the current changes in Python. As Python 2 sunsets, we are finally in an era where we can hope to someday use the features we see coming out of Python release again! Past changes in PythonLet’s start by a quick overview of the current state of Python 3. With Python
3.5 disappearing, we will simply mention that it brought the Python 3.6 was a big update, and possibly the most important Python 3 version to date. It was the very first version in the 3 series that was touted as “just as fast as Python 2.7” - the 3 series started life notoriously slow, due to the unicode strings and heavy internal changes. Python 3.6 brought f-strings, which were wildly popular and finally brought Python up to the level of Bash and Ruby for string interpolation. It has ordered dictionaries, simpler pathlib usage, and much more. It has a massive list of improvements and changes, feel free to check the official document. Python 3.7 was the first version actually claiming to be faster than 2.7. It also brought some nice changes, like officially ordered dictionaries to the language (not just a CPython implementation detail as in 3.6), and some nice additions to the standard library. There was also an OpenSSL update, which seems to have affected adoption rates. It has a fairly big list of improvements and changes, feel free to check the official document. And, of course, Python 3.8, which was released just a few days ago. The changes in general are a bit smaller than the last two versions, possibly due to the large change this year in how Python is governed. But let’s see what’s new! Positional-only argumentsLet’s take a function/class you’ve seen in the standard library, the humble dict: Here’s your challenge: write Okay, let’s try to use it: You have to use If you look at the signatures of That is now valid in a function definition in Python 3.8! Anything before the
This is now the full syntax for arguments: The walrus operatorAssignment in Python is a statement, which means it is quite limited. These are the only allowed ways you can make an assignment: But what about assigning in other places, like in the C languages? Up till now,
you could not do it. And there was a problem with adding it; if you just opened
up the The solution? A new operator!
Examples: You should use it carefully; this could make code harder to read. Also note that the scope leaks, which is useful in some cases and Pythonic, but means you can’t limit the scope of a variable using this syntax (which is one of the reasons C++17/C++20 added variable defines in several new places). f-string debuggingIn Python 3.6, f-strings make string interpolation easy, and were a runaway hit: Debugging a value, however, still requires you type it twice. This is now much
more A few notes:
Static typingStatic type hints are a big feature of Python 3, and now they are much more powerful: LiteralsYou can make make-shift enums now using Literals; these limit the values allowed for a variable in the typechecker: Note this really is just a Union of Literals, with a shortcut syntax for creating them. FinalYou can specify a “const” variable, one that is not allowed to be changed to something else later: ProtocolsThis is the C++20 Concepts / Java Interface idea; you define what methods and such a value should have: Now you can use Runtime helpersRuntime users of type hints get two big helpers: TypedASTTypedAST was merged into Python! The AST parser has gained a
Other featuresHere are a few other features of note:
Other developer changesLibrary developers may need to be aware of the following changes:
Final WordsPython.org downloads and Docker images were released on launch day. You can try
it for yourself with SourcesThis blog post was originally given as a talk at PyHEP 2019. Inspiration for the material within, along with good sources for further study: Categories: Python |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |