📝 Edit page
➕ Add page
Enum
Check if a value is in an allowed list
See Literal types in the docs.
Use Literal
or Final
for a single value.
a: Final = 19
b: Literal[19] = 19
Use the Literal
type for possible values.
Colors = Literal["red", "blue", "yellow"]
Example from the docs:
PrimaryColors = Literal["red", "blue", "yellow"]
SecondaryColors = Literal["purple", "green", "orange"]
AllowedColors = Literal[PrimaryColors, SecondaryColors]
def paint(color: AllowedColors) -> None:
pass
paint("red") # Valid
paint("turquoise") # Invalid