Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Python Programs - Functions

Function to return number of vowels in a string - Python Program

Example 1 :

def count_vowels(s): """Count vowels in string.""" vowels = "aeiouAEIOU" return sum(1 for ch in s if ch in vowels) str = input("Enter a String : ") str1="Programming" print("Number of vowels in the string '", str, "' is: ", count_vowels(str)) print("Number of vowels in the string '", str1, "' is: ", count_vowels(str1))

Output

 
OUTPUT 1 :
Enter a String  : Python
Number of vowels in the string ' Python ' is:  1
Number of vowels in the string ' Programming ' is:  3

OUTPUT 2 :
Enter a String  : Advanced Python
Number of vowels in the string ' Advanced Python ' is:  4
Number of vowels in the string ' Programming ' is:  3