PYTHON PROGRAMMING

Python Types: Optional Can Mean Mandatory

Learn how to avoid a frequent misuse and misunderstanding of typing.Optional.

Marcin Kozak
Towards Data Science
8 min readNov 21, 2023

--

Photo by Caroline Hall on Unsplash

According to the Python documentation, typing.Optional is a handy way to indicate that an object can be None. It’s a concise and elegant way to express this concept, but is it also crystal clear?

--

--

A full professor, interdisciplinary researcher, data scientist, statistician, Python, R and Go developer, open-source contributor — and a devoted writer