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 de…


This content originally appeared on DEV Community and was authored by Otmane Riad

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/


This content originally appeared on DEV Community and was authored by Otmane Riad


Print Share Comment Cite Upload Translate Updates
APA

Otmane Riad | Sciencx (2021-08-25T19:18:14+00:00) Get started with Python type hints. Retrieved from https://www.scien.cx/2021/08/25/get-started-with-python-type-hints/

MLA
" » Get started with Python type hints." Otmane Riad | Sciencx - Wednesday August 25, 2021, https://www.scien.cx/2021/08/25/get-started-with-python-type-hints/
HARVARD
Otmane Riad | Sciencx Wednesday August 25, 2021 » Get started with Python type hints., viewed ,<https://www.scien.cx/2021/08/25/get-started-with-python-type-hints/>
VANCOUVER
Otmane Riad | Sciencx - » Get started with Python type hints. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/25/get-started-with-python-type-hints/
CHICAGO
" » Get started with Python type hints." Otmane Riad | Sciencx - Accessed . https://www.scien.cx/2021/08/25/get-started-with-python-type-hints/
IEEE
" » Get started with Python type hints." Otmane Riad | Sciencx [Online]. Available: https://www.scien.cx/2021/08/25/get-started-with-python-type-hints/. [Accessed: ]
rf:citation
» Get started with Python type hints | Otmane Riad | Sciencx | https://www.scien.cx/2021/08/25/get-started-with-python-type-hints/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.