Editor

Build a TypedDict for API Response

Beginner · Write the code · from NamedTuple vs TypedDict vs Dataclass: Which to Choose?

From the lesson: NamedTuple vs TypedDict vs Dataclass: Which to Choose?

Python gives you three popular ways to bundle related data together: NamedTuple, TypedDict, and dataclass. Each one solves a slightly different problem.

Read the lesson

Create a TypedDict called ApiResponse with three fields: status (str), code (int), and data (str). Create an instance with status 'success', code 200, and data 'Hello'. Print the value of the 'status' key.

from typing import TypedDict
# Create your ApiResponse TypedDict here
# Create an instance and print the status

More NamedTuple and TypedDict exercises

All Python exercises · 50 practice problems · Object-Oriented Programming quiz