Check if String Starts with Vowel in Python

In the previous article, we had to check whether a character is a vowel or consonant. Here, we will check if the string starts with a vowel in python. The uppercase letters (A, E, I, O, U) and the lowercase letters (a, e, i, o, u) are the vowel letters. Except all other letters are consonant letters.

We will also develop a program to extract the words that start with a vowel from a list in python, and the Python program to accept strings starting with a vowel.

Python to Check if Word Starts with Vowel

In this program, we use the if-else statement to check if a word starts with a vowel or consonant. First, we have taken the string. Then, check if the 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 the 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 the String: Know Program
Know Program starts with consonant K

Enter the String: Everyone
Everyone starts with vowel E

Enter the String: Python
Python starts with consonant P

Enter the String: open
open starts with vowel o

In Python, the lower() function is a built-in method. It converts the characters from uppercase to lowercase.

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

string = input('Enter the 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 the String: ')

# calling function and display result
check(character)

Output:-

Enter the String: Know Program
Not Accept

Get notes to make your learning process easy. These are specially designed for beginners who want to learn coding through simple words, programs, and examples. You can use it as your reference and for revision purposes.

Notes Available:- Python, Java, C/C++, DSA, SQL, HTML CSS JavaScript, etc…

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do 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 *