My Code:
VowelsInString = False
String = 'bbbb000'
if 'a' or 'e' or 'i' or 'o' or 'u' in String:
VowelsInString = True
elif 'a' or 'e' or 'i' or 'o' or 'u' not in String:
VowelsInSting = False
So, I was expecting that when this ran, the if statement would be skipped and the VowelsInString would remain False, but upon running the code, the value of VowelsInString is True.
I expect that I may have done something wrong whilst typing the vowel checker if argument as I am fairly new to the concept of reading characters in strings. I would appreciate if someone would help me on debugging this code.
If that however is not the case, than I would, again, appreciate if someone would help on telling me what I've done wrong.
if re.search('a|e|i|o|u',string)
– Onyambu Jul 30 '18 at 19:11VowelsInString = any(v in String for v in 'aeiou')
You don't need anif/elif
for this, it can be done as a one-liner. – David Zemens Jul 30 '18 at 19:13