What is the reason of using enums | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок

What is the reason of using enums

I really didn't find a good reason for using enums. Looking at the example codes looks like they do the things more complicated instead of making them clear. Is there any real use of it in python in which without making use of it would be harder?

17th May 2020, 10:36 PM
Kleber Leal
Kleber Leal - avatar
1 ответ
Hi. The pourpose of enumeration in every language is give a natural representation to a series of values. Imagine you create a functión that return 0 if success otherwise return a values that is the error of the code. Now imagine there are 33 posible errors that can be returned by that function. It could be difficult to remember the meaning for every error value and maintain that code with no clue of what that value means. If you give a name acording to the error for every value you may have an idea of what that means, even if you didn't saw that code before.
18th May 2020, 3:35 AM
Benjamin Alejandro Luna
Benjamin Alejandro Luna - avatar