Are Enums like python dictionaries? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Are Enums like python dictionaries?

do the Enums elements work like the python dictionaries Keys?

25th Dec 2016, 1:59 PM
André Pires
André Pires - avatar
2 Answers
+ 2
While they seem the same superficially I wouldn't call them the same. An enum in Java/C++/C# is basically a classlike construct that has a fixed set of possible values. Usually these values are integers but Java and C# allow more complex values as well. They are commonly used for representing state or grouping common constants together. Python dictionaries are more like maps in Java. They store key/value pairs and can be changed whenever you like.
25th Dec 2016, 2:29 PM
James Durand
James Durand - avatar
0
I think ist more seamless to tuples than dictionaries. Tuples are inmutable like Enums also are
21st Jan 2021, 12:34 AM
David Ordás
David Ordás - avatar