What is Python type hints?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Python development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
Type hints (PEP 484, Python 3.5+) allow annotating variable and function types, making code more readable and enabling static analysis tools like mypy. Function annotation: def greet(name: str, age: int = 0) -> str: return f"Hi, {name}". Variable annotation: names: list[str] = []. Optional type: from typing import Optional; def find(id: int) -> Optional[str] (returns str or None). In Python 3.10+: str | None instead of Optional[str]. Common types from typing: List, Dict, Tuple, Set, Union, Callable, Any, TypeVar (now prefer built-ins: list[str], dict[str, int] in Python 3.9+). Type hints are not enforced at runtime — use mypy/pyright for static checking. They dramatically improve IDE autocomplete and catch bugs early.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last Python project, I used this when...' immediately makes your answer more credible and memorable.