Say I have an object called Tag, and I have three types of tags as indicated by an instance variable in the following way,
class Tag(object):
def __init__(self, name, type):
self.name = name
self.type = type
t1 = Tag("blue", "cold")
t2 = Tag("red", "warm")
t3 = Tag("black", "hot")
Let's say I only allowed three types: cold, warm, and hot. Would it be better to go checking if it is one of these types like this?
if t1.type == "cold":
# do something
elif t1.type == "warm":
# do something else
else t1.type == "hot":
# do something even elser
Or should I create an enum-like object like the one from this question,
class Type:
COLD=1
WARM=2
HOT=3
And instead create Tags like this?
t1 = Tag("blue", Type.COLD)
The reason I ask this question is because I heard a lot of processing power goes into comparing strings, and even though these are short 3, 4 letter long words, it is possible that I'd be making tens of thousands of comparisons of these types. Do you think its worth it to go creating enum objects for determining the type of an object as in the example I've shown above? Or is there a better way to do what I'm attempting to do?