🔵 🔵 🔵


Primary

၊၊||၊|။

typing.Optional ⚬|Documentation|1st|20260122195929-00-⌔

typing — Support for type hints — Python 3.14.2 documentation#typing.Optional

typing.Optional

Optional[X] is equivalent to X | None (or Union[X, None]).

Note that this is not the same concept as an optional argument, which is one that has a default. An optional argument with a default does not require the Optional qualifier on its type annotation just because it is optional. For example:

def foo(arg: int = 0) -> None:
   ...

On the other hand, if an explicit value of None is allowed, the use of Optional is appropriate, whether the argument is optional or not. For example:

def foo(arg: Optional[int] = None) -> None:
   ...

Changed in version 3.10: Optional can now be written as X | None. See union type expressions.

Printed 2026-06-28.

(echo:: @ )

Link to original

Secondary

• • •