Create a NamedTuple for RGB Colors
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 lessonCreate a NamedTuple called Color with three integer fields: red, green, and blue. Then create a color with values 255, 128, 0 and print it.
from typing import NamedTuple
# Create your Color NamedTuple here
# Create a color and print it
More NamedTuple and TypedDict exercises
- Build a TypedDict for API ResponseBeginner
- Predict the Output: ImmutabilityIntermediate
- Convert a Dict to a NamedTupleIntermediate
- Choose the Right ContainerAdvanced
All Python exercises · 50 practice problems · Object-Oriented Programming quiz