[Python] What is better Optional or | None in python type hints?

Discussão em 'Python' iniciado por Stack, Agosto 28, 2025.

  1. Stack

    Stack Membro Participativo

    There are two equeal ways to specify optional field, e.g. pydantic.

    class MyCLass(Baseodel):
    field1: Optional[StrInt]
    field2: StrInt| None


    Which way is better: field1 or field2?

    Continue reading...

Compartilhe esta Página