The latest version of Python has diverse new features and tweaks, all of which can be found in Python 3.7’s official documentation.
However, let’s have a look at the most essential upgrades:
breakpoint()
functionDebugging is an important part of programming, and Python 3.7 makes it more flexible and intuitive. The new breakpoint()
function replaces the older, more cumbersome syntax that is associated with previous versions of Python.
# Old breakpoint syntax:
def divide(a, b):
import pdb; pdb.set_trace()
return a / b
# New breakpoint syntax:
def divide(a, b):
breakpoint()
return a / b
The new data classes module makes it more convenient to create classes as special methods like .__init__()
, .__repr__()
, .__eq__()
, and several more are added automatically. Consider the following example that highlights the usage of a data class:
from dataclasses import dataclass, field@dataclass(order=True)class Employee:name: strage: intdesignation: float = field(repr=False, compare=False)minimumSalary: float = 5000def somefunc(self):pass# some stuff
The time
module has been upgraded such that each time
function returns the number of nanoseconds as an int
, rather than as a float
. These new functions are resolved three times faster than the older functions.
The accuracy is also increased because floating-point numbers are naturally inaccurate due to limitations in storing bits.
Type hints and annotations have been around since Python 3.5. However, they lacked performance and stability; Python 3.7 enhances their performance, improves core support, and allows forward references as well.
Dictionaries are now guaranteed to preserve insertion order. The normal dict
has replaced the older collections.OrderedDict
in most cases. The dict
feature was informally implemented in Python 3.6, but it is now officially documented in Python 3.7.
Python 3.7 is significantly faster than its predecessor, speed-ups include:
typing
module is seven times faster.Free Resources