AI engineering glossary · Python advanced
What is optional type?
Optional type: A type hint meaning a value may be of a given type or None, written Optional[int] or int | None. It documents functions that may return nothing and prompts callers to handle the missing case.
Optional type: an example
def find_user(id) -> str | None: returns a name or None if the id is not found.
Related terms
More Python advanced terms
Where you learn it
Optional type is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.