Strings · Python example
Count the vowels in a sentence with a loop and a membership test.
A membership test with in checks whether a character belongs to a group. Lowercasing the text makes the count case-insensitive.
text = "The quick brown fox jumps over the lazy dog"
vowels = "aeiou"
count = 0
for char in text.lower():
if char in vowels:
count += 1
print(f"Vowels: {count}")