S
S
SoursXond2021-11-04 05:02:45
Python
SoursXond, 2021-11-04 05:02:45

How to create an optional data type in python?

In StandartML, it was possible to organize your own data type, where you could outline the possible options . The

datatype colour = red | blue | green

question is whether it is possible (and whether it is generally advisable) to write something similar in python?
That is, should there be a data type (class) that can have only a few values?

Ideally, I would like to see something like this:
color1 = Color(RED)orcolor1 = Color(s)(Сolors.RED)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bqio, 2021-11-04
@SoursXond

https://docs.python.org/3/library/enum.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question