At the core of Python programming is a thorough knowledge of Python 3 versions. In What's New in Python 3.7, you will learn how to use all of Python 3.7's new features. First, you will learn data classes. Next, you will explore the new breakpoint functionality. Finally, you will discover how to test the performance of your applications and benefit from Python 3.7's speed improvements. When you are finished with this course, you will have a foundational knowledge of Python 3.7 that will help you as you move forward to develop Python 3 applications.
Course Overview Hi everyone. My name is Anthony Shaw, and welcome to my course, What's New in Python 3. 7. I'm a Python enthusiast at Dimension Data. The Python Software Foundation have shipped the newest version of Python, 3. 7. This new version is not only the fastest version of Python ever, but it's also packed with new and exciting features. In this course, we're going to walk through all of these amazing new features in Python 3. 7. Some of the major topics we will cover include the new data classes module, whether your applications will run faster, and changes to breakpoints. By the end of this course, you'll know how to get started with Python 3. 7 and take advantage of all that it offers. Before beginning the course, you should really be familiar with the basics of Python 3, and from here, you should feel comfortable diving into Python 3 with courses on performance and optimization and data structures and advanced classes. I hope you'll join me on this journey to learn Python 3. 7 with the What's New in Python 3. 7 course, at Pluralsight.
Changes to Locales and UTF-8 Mode Python 3 introduced a revolutionary change to text and data types. The idea was to better support Unicode and avoid errors when encountering special characters. This introduced over time various challenges in dealing with both non-Unicode-compatible systems and data where encoding is not specifically known. Now, if you're not up to scratch on the details between Unicode and UTF-8 or the differences between text and binary data in Python 3, I recommend you watch the third module called Changes to Core Types in my Migrating from Python 2 to 3 course. I go into a lot more detail about what Unicode is, how it works, and why you need to care. Python 3 makes some changes to the way the default locale, and therefore the default encoding, is established, and it introduces a new flag called UTF-8 mode for overriding it. Before we go into those changes, I recommend reading up on Unicode first.
The Built-in Breakpoint Function Python 3. 7 implements a new way to write breakpoints and instantiate debuggers within your code. Calling breakpoint from anywhere in Python 3. 7 will now enter a debugging session. Something of an oddity in Python is the lack of a standard way to mark a line of code as a breakpoint. Instead, the standard libraries had the pdb, or Python debug module, for many years with a common pattern of writing import pdb; pdb. set_trace on a line and that inserts breakpoint. There are three main issues with this approach. First, it's obtuse for beginners. The "can I put a breakpoint in a running Python program" question on Stack Overflow has been viewed over 20, 000 times. You can't toggle the on and off in execution. If you accidently leave a breakpoint in your code, that's tough. Your code will hang when it's hit. And thirdly, the debugger library is hardcoded into the breakpoint statement. There are other and also better debugging libraries for Python. You might also want to select a different debugger, depending on how your code is being executed, for example, in a unit test or on a multi-threaded server. Python 3. 7 implements PEP 553, which sets the standard for executing a breakpoint inside of a block of Python code.
Changes to the Time Module Python 3. 7 introduces new functions in the time module within the standard library. These functions complement the existing ones for fetching or setting the current time. They now offer nanosecond resolution. If you're thinking this change doesn't impact you because you don't need to measure things down to the nanosecond, the functions also now use Python integers instead of floating point numbers. This means you no longer have to worry about the inaccuracies of floating point arithmetic in time module functions. And as such, the accuracy of these new functions is between 2 to 3 times better.
Changes to Type Annotations Python 3. 7 introduces a backward-incompatible change to the way type annotations are evaluated. Instead of being evaluated at import just like any other Python code, they will now be evaluated on demand. This change will be optional in Python 3. 7, enabled through the import of a dunder future statement. But in Python 4. 0, yes, you heard me right, Python 4. 0, this will be the default behavior. Typing module was introduced in Python 3. 5 on a provisional basis. This label means that new features might be added, and APIs might change between minor releases. That has happened with Python 3. 5 and 3. 6 in the introduction of new features, but as more people have been using type hinting, it became apparent that the up-front evaluation of type annotations was the wrong approach. Python 3. 7 moves to delay those evaluations and make them strings instead of typed attributes.
Performance Improvements One of the most exciting changes in Python 3. 7 is that it's the fastest version of Python ever. In this module, I'm going to explain what changed to make Python 3. 7 faster, what the impacts may be on our applications, and how to compare the performance between different Python runtimes. Before we do that, I wanted to put a bit of context in around Python performance. Now when I say Python, I'm normally talking about CPython, the distribution that you download from python. org. There are other Python interpreters out there such as PyPy, which have pros and cons over the CPython interpreter. CPython has gone on quite the journey over the past decade with a big transition from 2 to 3. Python 2. 7 was the fastest release of the 2. X series, with further optimizations being added later. Python 3 came out, and the early, now deprecated versions of Python 3, 3. 0 to 3. 3 had some challenges with memory consumption, startup time, and the overall speed. The first comparable release of Python 3 to the performance of 2. 7 was the 3. 6 release. And now the 3. 7 release of Python is significantly faster than 2. 7 and any other version of Python before it. So if you're putting off migrating to Python 3 for performance reasons, this is a big reason to finally make the jump. Make sure you watch my course, Migrating from Python 2 to 3, if you have a lot of code to move.