DEV Community

Cover image for Get started with Python type hints
Otmane Riad
Otmane Riad

Posted on

Get started with Python type hints

Python is best thought of as a “dynamic, but strongly typed” language. Types aren’t associated with the names for things, but with the things themselves.

This makes Python flexible and convenient for developers, because you don’t have to rigorously define and track variable types if you’re just throwing together a quick-and-dirty script. But for bigger projects, especially libraries used by third parties, it helps to know which object types are associated with which variables.

For some time now, Python has had the ability to “annotate” names with type information, in one form or another. With Python 3.5, type hints officially became part of the language (PEP 484). Using a linter or code-checking tool, developers can check the consistency of variables and their types across a code base, and perform static analyses of code that would previously have been difficult or impossible. All this is done ahead of time, before the code runs.

In this article we’ll explore some basic examples of Python type hinting. But first we’ll clear up a common misunderstanding about what it is and isn’t used for.

Read More: https://hitechnoloy.ca/get-started-with-python-type-hints/

Top comments (2)

Collapse
 
aatmaj profile image
Aatmaj

Good post.

Collapse
 
nexteventideas profile image
Otmane Riad

thank you sir