I have a code in Python and want to find vowels in a string.
The code I have written is following….I tried different combinations for using For-Loop, but it throws two different errors;
- ‘int’ object is not iterable,
- string indices must be integers, not str.
how can I find all vowels in a line?
str1 = 'sator arepo tenet opera rotas'
vow1 = [str1[i] for i in str1 if str1[i] is 'a' | 'e' | 'o']
what about:
You’re getting errors because when you loop over a string, you loop over the characters in the string (not string indices) and because
'a' | 'e' | 'o'doesn’t make sense for strings — (they don’t support the|operator)One final comment, you shouldn’t use
isto test for equality.istests for identity. A simple test:The reason is because
aandbreference different objects that have the same value.