Feb-26-2018, 03:21 AM
previously i had asked which was better:
so, now, between
word[0] in ('w','x','y','z')
vs word[0] in 'wxyz'
. but now i have a new variation on the problem. the value for word might be an empty string so i need to change word[0]
to word[:1]
to avoid an exception i don't want to happen. that means i could be doing the test word[:1] in 'wxyz'
with an empty string which would always give a True value for the in operation. so i can't use that one at all and apparently must use word[:1] in ('w','x','y','z')
to perform a correct test. the only alternative i can imagine is word[:1] and word[:1] in 'wxyz'
.so, now, between
word[:1] in ('w','x','y','z')
and word[:1] and word[:1] in 'wxyz'
which is the best choice? or is there something even better that i have overlooked?