Editor

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 lesson

Create 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

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