'What's the difference between these snippets of code?
Beginner here so please excuse me if this is really obvious.
The intention of the code I have written is to read my_string backwards, and print all vowels it identifies.
Can anybody explain why my first method here does not work? Instead of printing only the vowels, it prints all characters.
for letter in my_string[::-1]:
if letter == "a" or "e" or "i" or "o" or "u":
print(letter)
Wheras my second method below, does work as intended.
for letter in my_string[::-1]:
if letter in 'aeiou':
print(letter)
What is the logic behind this? My own monkey-brain logic tells me that both methods should work. Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
