typing Module

List, Dict, Optional, Union

Interview Relevant: Type system

The typing Module

Provides types for complex structures.

Code Examples

python
1from typing import List, Dict, Optional, Union
2
3def process_items(items: List[int]) -> None:
4    pass
5
6def find_user(id: int) -> Optional[str]:
7    return "Alice" if id > 0 else None
8
9def parse(value: Union[int, str]) -> int:
10    return int(value)

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In