Quiz de Python: Type Hints

This Python quiz checks how well you understand type hints, from int | None and list[str] to Callable, Literal and NamedTuple. It also tests the most common misunderstanding of all - that Python checks your hints when the code runs.

Médio 10 perguntas ~6 minutos Aprovação com 80% Python 3.12

Escolha um modo

Jogando como visitante: entre para guardar seu XP e sua sequência.

Pergunta de exemplo

Pergunta 1 de 10

What does this print?

def add(a: int, b: int) -> int:
    return a + b

print(add("4", "2"))
Mostrar a resposta

C. 42 Python does not check type hints when the code runs. The two strings are simply joined with +, giving 42. A static checker like mypy would flag this call before you run it.

O que este quiz cobre

  • Hints are not enforced at run time
  • int | None, list[str] and dict[str, int]
  • Callable, Literal and NamedTuple
  • __annotations__ and static checkers like mypy
  • Hints and isinstance()

Perguntas frequentes

Preciso de uma conta?

Não. Qualquer pessoa pode jogar. Entre para guardar seu XP, sequência, badges e histórico.

Qual versão do Python?

Python 3.12. Toda pergunta sobre a saída foi conferida rodando o código.

Posso refazer?

Pode. Sua melhor nota fica salva, e as perguntas e respostas são embaralhadas a cada vez.