Python Program to Count vowels in String

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

  1. Python Program to Convert Uppercase to Lowercase
  2. Convert String Lowercase to Uppercase in Python
  3. Python First Character of String Uppercase
  4. Python Concatenate String and Variable (int, float, etc)
  5. How to Find Length of String in Python
  6. Python: String Join Function
  7. Python String Append Examples
  8. How to replace a character in a string in python
  9. Python – Count Number of Occurrences in String
  10. Python Remove Last Character from String
  11. Python Remove Character From String
  12. Python Program to Reverse String
  13. Python Program to Remove First Occurrence of Character in a String
  14. Python: Remove Special Characters from String
  15. Python Program to Swap Two Character of Given String
  16. Python Program String Find
  17. Python: Two Given Strings and Swap First Two Characters of Each String
  18. Print All Permutations of Given String in Python
  19. Python | Check Whether a String Contains Number or Letter
  20. Python: Convert String to Float & Float to String
  21. Python Program to Reverse String Using Stack
  22. How To Convert Python Int to String and String to Int
  23. Python Convert String to List and List to String

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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