
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program to accept string starting with vowel
When it is required to accept a string that starts with a vowel, a ‘startswith’ function is used to check if the string begins with a specific character (vowel) or not.
Example
Below is a demonstration of the same
my_list = ["Hi", "there", "how", "are", "u", "doing"] print("The list is : ") print(my_list) my_result = [] vowel = "aeiou" for sub in my_list: flag = False for letter in vowel: if sub.startswith(letter): flag = True break if flag: my_result.append(sub) print("The resultant string is : ") print(my_result)
Output
The list is : ["Hi", "there", "how", "are", "u", "doing"] The resultant string is : ['are', 'u']
Explanation
A list is defined and is displayed on the console.
An empty list is defined.
The vowels are defined in a string.
The list is iterated over and a ‘flag’ variable is assigned to False.
The letters in the string are compared to the vowel string.
The ‘startswith’ method is used to check if a string in the list begins with a vowel.
If yes, it is displayed on the console.
- Related Articles
- Python Program that extract words starting with Vowel From A list
- Python Program to accept string ending with alphanumeric character
- Python program to check if the given string is vowel Palindrome
- Program to count sorted vowel strings in Python
- Java program to check occurence of each vowel in String
- Java program to check occurrence of each vowel in String
- Program to find length of longest substring with even vowel counts in Python
- Python program to accept the strings which contains all vowels
- Smallest String Starting From Leaf in Python
- Distance to nearest vowel in a string - JavaScript
- How can I filter string value with starting letter?
- Draw DFA which accepts the string starting with ‘ab’.
- Alternate vowel and consonant string in C++
- Program to shuffle string with given indices in Python
- Print all Subsequences of String which Start with Vowel and End with Consonant in C++

Advertisements