(Nov-12-2018, 07:25 AM)Scottx125 Wrote: As far as I can tell not means if the value is zero
I am not sure what you meany by this.
not
will toggle the boolean, i.e. True will become False, and False will become True. I don't know what your reasoning not to use
not
in C/C++ is, but this is python.
'{0}'.format(authorindex) in votelist
is True or False, i.e. already boolean.
using
not '{0}'.format(authorindex) in votelist
is more readable, cleaner, simple, etc. And does not require using brackets (i.e. your initial problem was due to interpreter evaluating from right to left, so your original code was actually equivalent to
if '{0}'.format(authorindex) in (votelist == False):
- brackets added by me for explanation)
Also PEP8 is clear with recommendation in this case
Quote:Don't compare boolean values to True or False using ==.
Yes: if greeting:
No: if greeting == True:
Worse: if greeting is True:
and something else, I should have mentioned already
assuming
authorindex
is a variable that is not str and you want to check if it is in list that hold several str variables, it's better to use str() function, instead of string formatting (i.e. you use string formatting just to cast the autorindex to str).
1 |
if not str (authorindex) in votelist:
|