1

I was playing around with python enums and noticed this behavior. So, I create an enum class as follows;

from enum import Enum
class T(Enum):
    A = 1,
    B = 2,
    C = 3

Now, I do:

s = T.A
print(s.value)

This prints (1,). Also, type(s.value) is a tuple. This is a bit strange to me. Why is it wrapping the enum values as tuples?

Luca
  • 10,458
  • 24
  • 107
  • 234
  • 2
    Because the values *are* tuples, except the last one; that's what the comma means. – jonrsharpe Sep 13 '18 at 13:53
  • 1
    @jonrsharpe So instead of writing an answer, you choose to downvote? there are numerous examples which interpret this as int. Here is a reputable one: https://www.geeksforgeeks.org/enum-in-python/ The behaviour shown here is completely not what I reproduce. print ("The value associated with dog is : ",end="") print (mem.value) The value associated with dog is : 1 – Luca Sep 13 '18 at 13:55
  • And that reputable example **doesn't have commas**. – jonrsharpe Sep 13 '18 at 13:55
  • 1
    Please stop blaming the downvotes on the people who comment on your question. jon isn't the only person who's seen your question, and it's fairly unlikely that the downvote is his. If you're too confrontational, all you'll achieve is that people will stop commenting altogether. – Aran-Fey Sep 13 '18 at 13:59
  • @Aran-Fey Not blaming the downvote. Blaming downvotes without explanation. – Luca Sep 13 '18 at 14:01
  • That is completely besides the point. If you don't know who's to blame, don't pin the blame on the first person you see. – Aran-Fey Sep 13 '18 at 14:02
  • Please note that my first comment was a response to the last sentence of your question, *not* your first comment (which you wrote while I was writing mine). – jonrsharpe Sep 13 '18 at 14:04
  • Apologies if I offended. – Luca Sep 13 '18 at 14:05

0 Answers0