Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

checking if the first letter of a word is a vowel

I am trying to use python to write a function that checks whether the first letter of a given word, for instance "ball" is a vowel in either uppercase or lowercase. So for instance:

#here is a variable containing a word:
my_word = "Acrobat"

#letters in vowel as a list
the_vowel = ["a","e","i","o","u"]

How do a check that the first letter in "Acrobat" is one of the vowels in the list? I also need to take into consideration whether it is upper or lowercase?

like image 843
Bola Owoade Avatar asked Nov 14 '12 12:11

Bola Owoade


2 Answers

try my_word[0].lower() in the_vowel

like image 179
gefei Avatar answered Sep 23 '22 21:09

gefei


I don't know if it is better than the answers already posted here, but you could also do:

vowels = ('a','e','i','o','u','A','E','I','O','U')
myWord.startswith(vowels)
like image 42
Matt Avatar answered Sep 21 '22 21:09

Matt