- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to count the number of vowels using set in a given string
We will count the number of vowels using set in a given string. Let’s say we have the following input −
jackofalltrades
The output should be the following, counting the number of vowels −
65
Count the number of vowels using set in a given string
We will count the number of vowels using set in a give string −
Example
def vowelFunc(str): c = 0 # Create a set of vowels s="aeiouAEIOU" v = set(s) # Loop to traverse the alphabet in the given string for alpha in str: # If alphabet is present # in set vowel if alpha in v: c = c + 1 print("Count of Vowels = ", c) # Driver code str = input("Enter the string = ") vowelFunc(str)
Output
Enter the string = howareyou Count of Vowels = 5
Count the number of vowels using set in a given string without using a function
We will count the number of vowels using set without using a function −
Example
# string to be checked myStr = "masterofnone" count = 0 print("Our String = ",myStr) # Vowel Set vowels = set("aeiouAEIOU") # Loop through, check and count the vowels for alpha in myStr: if alpha in vowels: count += 1 print("Count of Vowels = ",count)
Output
Our String = masterofnone Count of Vowels = 5
- Related Articles
- Python program to count number of vowels using set in a given string
- Python program to count the number of vowels using sets in a given string
- How to Count the Number of Vowels in a string using Python?
- Java program to count the number of vowels in a given sentence
- C++ Program to count Vowels in a string using Pointer?
- C# Program to count number of Vowels and Consonants in a string
- To count Vowels in a string using Pointer in C++ Program
- Java Program to count vowels in a string
- C# Program to count vowels in a string
- Count the number of vowels occurring in all the substrings of given string in C++
- Java Program to count all vowels in a string
- Count the pairs of vowels in the given string in C++
- C Program to count vowels, digits, spaces, consonants using the string concepts
- Count and display vowels in a string in Python
- Java Program to Count the Number of Vowels and Consonants in a Sentence

Advertisements