Python program: Vowel or consonant
Check whether each letter of a word is a vowel or a consonant.
The code
word = "Python" for ch in word: if not ch.isalpha(): continue kind = "vowel" if ch.lower() in "aeiou" else "consonant" print(ch, kind)
Output
P consonant y consonant t consonant h consonant o vowel n consonant
How it works
in "aeiou" checks membership in a string. Lower-casing first means capitals are handled too.
Python features used
Learn the ideas behind it in the free lesson Strings.