Check if String Starts with Vowel in Python

Previously we have to check whether a character is a vowel or consonant. Now in this post, we will check if the string starts with a vowel in python. In the English language, the letters A, E, I, O, U, and a, e, i, o, u are defined as a vowel. Except these all other letters are consonants. We will also develop a program to extract the words that start with a vowel from a list in python, and a Python program to accept strings starting with a vowel.

Python to Check if Word Starts with Vowel

This python program using the if-else statement to check if a word starts with a vowel or consonant. We will take a string while declaring the variables. Then, check if string starts with a vowel in python using the if-else statement. Finally, the result will be displayed on the screen.

# Python program to check if string starts with vowel

# take inputs
string = input('Enter any String: ')

# vowel alphabet
vowel = 'aeiou'

# check string starts with vowel or consonant
if string[0].lower() in vowel:
   print(string,'starts with vowel',string[0])
else:
   print(string,'starts with consonant',string[0])

Output for the different input values:-

Enter any String: Know Program
Know Program starts with consonant K

Enter any String: Everyone
Everyone starts with vowel E

Enter any String: Python
Python starts with consonant P

Enter any String: open
open starts with vowel o

The lower() method returns the lowercased string from the given string. It converts all uppercase characters to lowercase. If no uppercase characters exist, it returns the original string.

We can also write a program in a simple way to check if a string starts with a vowel or consonant.

string = input('Enter any String: ')

if string[0].lower() in ['aeiou']:
    print(string,'starts with vowel',string[0])
else:
    print(string,'starts with consonant',string[0])

Q) Write a code to check if the string in input_str starts with a vowel or not. print capital yes or no.

input_str = 'Know Program'

if input_str[0].lower() in ['aeiou']:
    print('YES')
else:
    print('NO')

Output:- No

Write a Program Which Extracts all the Words Which Starts with the Vowel in Python

We will develop a program to extract the words that start with a vowel from a list in python using startswith() and for loop. In this, we check for each word and check if it starts with a vowel using startswith() on the first alphabet of every word. The iteration part is done using the loop. Finally, print all the words that start with a vowel.

# Python program to extract the words that start with a vowel from a list

# take list
words = ['String','Egg','know','Open','program','animal']

# vowel alphabet
vowel = 'A','E','I','O','U','a','e','i','o','u'

# check words and display result
print([w for w in words if w.startswith(vowel)])

Output:-

[‘Egg’, ‘Open’, ‘animal’]


Q) Extract the words that start with a vowel from a list input_list=[wood, old, apple, big, item, euphoria] using list comprehensions.


input_list = ['wood', 'old', 'apple', 'big', 'item', 'euphoria']
print([input_list for input_list in input_list if input_list[0] in 'aeiou'])

Output:- [‘old’, ‘apple’, ‘item’, ‘euphoria’]

Python Program to accept Strings starting with a Vowel

These are the different methods to check whether a string starts with a vowel or consonant. In this program, we can also take the help of a user-defined function. A function is a block of code that performs a specific task.

# Python program to accept strings starting with a vowel
  
# Function to check if first character is vowel
def Vowel(string):
  
    if (string[0] == 'A' or string[0] == 'a'
        or string[0] == 'E' or string[0] == 'e'
        or string[0] == 'I' or string[0] == 'i'
        or string[0] == 'O' or string[0] == 'o'
        or string[0] == 'U' or string[0] == 'u'):
        return 1
    else:
        return 0
  
# Function to check
def check(string):
    if (Vowel(string)):
        print('Accept')
    else:
        print('Not Accept')

# take input
character = input('Enter any String: ')

# calling function and display result
check(character)

Output:-

Enter any String: Know Program
Not Accept

Also See:- Print Vowels in a String in Python, & Count Vowels in a String in Python

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *