Enum doesn't understand what I want to set it to
this probably seems a little obvious to you, and I'm sure once I figure it out I will feel pretty beat up myself. But for the life of me, I can't figure out what's wrong. My teacher used this strip of code to explain how enum's work, but he never ran it, and when I run it, I keep getting back a weird result. Here is the entire code below:
from enum import Enum
class Shape(Enum):
SQUARE = 2
DIAMOND = 1
CIRCLE = 3
ALIAS_FOR_SQUARE = 2
if Shape.SQUARE == Shape.DIAMOND:
print("SQUARE == DIAMOND")
else:
print("SQUARE != DIAMOND")
if Shape.SQUARE == 2:
print("SQUARE == 2")
else:
print("SQUARE != 2")
After I run everything through, the prints are as follows
SQUARE != DIAMOND (Expected)
SQUARE != 2 (Unexpected)
For some reason, it says square isn't two when I've triple checked that it was set to 2, and I don't see anywhere else that it would have been altered
from Recent Questions - Stack Overflow https://ift.tt/3cbulII
https://ift.tt/eA8V8J
Comments
Post a Comment