I'm a beginner when it's about Python, and I do not quite understand the following:
I try to print the indices of all the vowels that are in the string:
string = "And now for something completely different"
vowel = "aeiouAEIOU"
for i in range(0, len(string)):
if i in vowel:
print(string[i])
[0, 5, 9, 13, 15, 18, 23, 27, 29, 34, 37, 39]
"'in <string>' requires string as left operand, not int"
You are trying to check if i
, which is an integer, is included in the string vowel
.
string = "And now for something completely different"
vowel = "aeiouAEIOU"
for i in range(0, len(string)):
if string[i] in vowel:
print(string[i])
By doing this you will print each character in the string that fulfill the inclusion condition.