I just caught an issue with something I wrote, and was hoping I could get a proper explanation of what was happening, and the best way to get around it. I have a fix in place, but am not sure if it's the best solution
I have a variable interval
that is a string. In this scenario, let's say interval = 'Day'
Code compares this against a tuple in an if
and elif
expression:
if interval in ('FiscalWeekDaily','Daily'):
...
...
elif interval in ('DayHourly'):
Now I thought 'Day' in ('DayHourly')
would evaluate as False
but it turns out it evaluates to True
. What's the exact explanation for this? I would assume that since there is only 1 element, 'Day' is being compared against that element.
So if I try 'Day' in ('DayHourly', 'whatever')
, that evaluates as False
because 'Day' is evaluated against each element, right?
So my fix is simply elif interval in ['DayHourly']:
. Is that the proper way to go about doing this?