Python program to count the number of vowels in string; In this python tutorial, we would love to share with you how to count vowels in a given string python using for loop, function and ascii value.
How to count the vowels in a string in Python
See the following python program to count number of vowels in a string:
- 1: How to count number of vowels in a string in python using for loop
- 2: Python Program to Count Vowels in string Using For loop and Lower() function
- 3: Program to Count Total Number of Vowels in a String Using ASCII Value
1: How to count number of vowels in a string in python using for loop
Use the following steps and write a python program to count number of vowels in a string using for loop:
- Take input string from the user.
- Count vowels in string using for loop and if statement.
- Inside the For Loop, we are using If Statement to check whether the character is a, e, i, o, u, A, E, I, O, U. If true, increment the vowels value otherwise, skip that character.
- Print result.
# Python Program to Count Vowels in a String str1 = input("Please Enter Your Own String : ") vowels = 0 for i in str1: if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u' or i == 'A' or i == 'E' or i == 'I' or i == 'O' or i == 'U'): vowels = vowels + 1 print("Total Number of Vowels in this String = ", vowels)
After executing the program, the output will be:
Please Enter Your Own String : hello world Total Number of Vowels in this String = 3
2: Python Program to Count Vowels in string Using For loop and Lower() function
Use the following steps and write a python program to count number of vowels in a string using function:
- Take input string from the user.
- Convert string to lowercase using lower() function.
- Count vowels in string using for loop and if statement.
- Inside the For Loop, we are using If Statement to check whether the character is a, e, i, o, u. If true, increment the vowels value otherwise, skip that character.
- Print result.
# Python Program to Count Vowels in a String str1 = input("Please Enter Your Own String : ") vowels = 0 str1.lower() for i in str1: if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u'): vowels = vowels + 1 print("Total Number of Vowels in this String = ", vowels)
After executing the program, the output will be:
Please Enter Your Own String : hello World Total Number of Vowels in this String = 3
3: Program to Count Total Number of Vowels in a String Using ASCII Value
Use the following steps and write a python program to count number of vowels in a string using ASCII value:
- Take input string from the user.
- Count vowels in string using for loop, if statement, and ord() function.
- Inside the For Loop, we are using If Statement to check whether the character is a, e, i, o, u, A, E, I, O, U by using ord() function. If true, increment the vowels value otherwise, skip that character.
- Print result.
# Python Program to Count Vowels in a String str1 = input("Please Enter Your Own String : ") vowels = 0 for i in str1: if(ord(i) == 65 or ord(i) == 69 or ord(i) == 73 or ord(i) == 79 or ord(i) == 85 or ord(i) == 97 or ord(i) == 101 or ord(i) == 105 or ord(i) == 111 or ord(i) == 117): vowels = vowels + 1 print("Total Number of Vowels in this String = ", vowels)
After executing the program, the output will be:
Please Enter Your Own String : you are a good developer Total Number of Vowels in this String = 11
Recommended Python String Programs
- Python Program to Convert Uppercase to Lowercase
- Convert String Lowercase to Uppercase in Python
- Python First Character of String Uppercase
- Python Concatenate String and Variable (int, float, etc)
- How to Find Length of String in Python
- Python: String Join Function
- Python String Append Examples
- How to replace a character in a string in python
- Python – Count Number of Occurrences in String
- Python Remove Last Character from String
- Python Remove Character From String
- Python Program to Reverse String
- Python Program to Remove First Occurrence of Character in a String
- Python: Remove Special Characters from String
- Python Program to Swap Two Character of Given String
- Python Program String Find
- Python: Two Given Strings and Swap First Two Characters of Each String
- Print All Permutations of Given String in Python
- Python | Check Whether a String Contains Number or Letter
- Python: Convert String to Float & Float to String
- Python Program to Reverse String Using Stack
- How To Convert Python Int to String and String to Int
- Python Convert String to List and List to String