Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Complex types for Python 3.8 and before

  • List
  • Dict
  • Set
  • Tuple
from typing import List, Dict, Tuple

things: List = ["snake", 42]
#things: List[str] = ["snake", 42]

numbers: List[int] = [23, 19, 42]

mapping: Dict[str, int] = {
        "Perl": 4,
        "Python": 6,
        "Rust": 4,
        "PHP": 3
}


info: Tuple[str, int, bool] = ("Python", 3, True)