Type hinting
Since Python 3.5, we’ve had a feature called type hinting, which is arguably one of the most useful additions to Python 3. It allows you to specify the types of variables and return values, which means your editor will be able to give you smart autocompletion. This makes it useful for all Python programmers, regardless of level, and can make your life much easier when paired with a good editor.
Basic example
Most editors are already smart enough to recognize basic types in regular variables such as these:
>>> a = 123
>>> b = 'test'
>>> c = True
It becomes a lot harder for an editor when, instead of a = 123
, we have something like a = some_function()
. In some cases, the return type of a function is obvious (i.e. return True
), but if the return type depends on the input variables or is not consistent, it becomes much harder for the editor to understand what is happening.
As the Zen of Python tells us, explicit...