{"id":124664,"date":"2022-05-09T16:25:33","date_gmt":"2022-05-09T16:25:33","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=344950"},"modified":"2022-05-09T16:25:33","modified_gmt":"2022-05-09T16:25:33","slug":"how-to-count-vowels-in-a-string","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2022\/05\/09\/how-to-count-vowels-in-a-string\/","title":{"rendered":"How to Count Vowels in a String"},"content":{"rendered":"<div class=\"kk-star-ratings kksr-valign-top kksr-align-left \" data-payload=\"{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;344950&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;top&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;count&quot;:&quot;0&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;}\">\n<div class=\"kksr-stars\">\n<div class=\"kksr-stars-inactive\">\n<div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div class=\"kksr-legend\"> <span class=\"kksr-muted\">Rate this post<\/span> <\/div>\n<\/div>\n<h2 class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">Problem Formulation and Solution Overview<\/h2>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">In this article, you&#8217;ll learn how to <strong>count the number of vowels in a string<\/strong>. <\/p>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">To make it more fun, we have the following running scenario:<\/p>\n<p><em>In Canada, we have a province called <a rel=\"noreferrer noopener\" href=\"https:\/\/www.saskatchewan.ca\/\" data-type=\"URL\" data-id=\"https:\/\/www.saskatchewan.ca\/\" target=\"_blank\">Saskatchewan<\/a>. This province has a large amount of flat land. In this article, we reference their local saying. <\/em><\/p>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio has-global-color-8-background-color has-background\"><em><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/13.1.0\/72x72\/1f4ac.png\" alt=\"\ud83d\udcac\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Question<\/strong>: How would we write Python code to count the vowels in a String?<\/em><\/p>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">We can accomplish this task by one of the following options:<\/p>\n<ul type=\"video\" class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">\n<li><strong>Method 1<\/strong>: Use <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-regex-search\/\" target=\"_blank\">Regex<\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-dictionary-comprehension\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-dictionary-comprehension\/\" target=\"_blank\">Dictionary Comprehension<\/a><\/li>\n<li><strong>Method 2<\/strong>: Use <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/list-comprehension\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/list-comprehension\/\" target=\"_blank\">List Comprehension<\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-list-count\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-list-count\/\" target=\"_blank\"><code>count()<\/code><\/a><\/li>\n<li><strong>Method 3<\/strong>: Use <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/collections.html\" data-type=\"URL\" data-id=\"https:\/\/docs.python.org\/3\/library\/collections.html\" target=\"_blank\"><code>Counter()<\/code><\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/collections.html\" data-type=\"URL\" data-id=\"https:\/\/docs.python.org\/3\/library\/collections.html\" target=\"_blank\"><code>count.update()<\/code><\/a><\/li>\n<li><strong>Method 4<\/strong>: Use <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-loops\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-loops\/\" target=\"_blank\"><code>for<\/code><\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-list-count\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-list-count\/\" target=\"_blank\"><code>count()<\/code><\/a><\/li>\n<li><strong>Method 5<\/strong>: Use <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-map\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-map\/\" target=\"_blank\"><code>map()<\/code><\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-list-count\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-list-count\/\" target=\"_blank\"><code>count()<\/code><\/a><\/li>\n<\/ul>\n<hr class=\"wp-block-separator\"\/>\n<p id=\"block-3b5c9c73-276c-4b84-a1bc-d5ba1de38d56\">Add the following code to the top of each code snippet. This snippet will allow the code in this article to run error-free.<\/p>\n<pre class=\"EnlighterJSRAW wp-embed-aspect-16-9 wp-has-aspect-ratio\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import re\nfrom collections import Counter<\/pre>\n<hr class=\"wp-block-separator\"\/>\n<h2>Method 1: Use Regex and Dictionary Comprehension<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">This example uses <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-regex-search\/\" target=\"_blank\"><code>Regex<\/code><\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-dictionary-comprehension\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-dictionary-comprehension\/\" target=\"_blank\"><code>Dictionary Comprehension<\/code><\/a> as a one-liner to tally the number of specified vowels in a string. The results return in a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-dictionary\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-dictionary\/\" target=\"_blank\">Dictionary<\/a> format.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"2\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">saying = 'Saskatchewan! Where you can watch your dog run away for 3 days.'\nvcount = {x: len(re.findall(f\"{x}\", saying.lower())) for x in 'aeiou'}\nprint(vcount)<\/pre>\n<p class=\"has-text-align-center has-base-3-color has-accent-background-color has-text-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/13.1.0\/72x72\/2b50.png\" alt=\"\u2b50\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/>A Finxter Favorite!<\/p>\n<p>This code declares the string <code>saying<\/code>. Then, <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/list-comprehension\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/list-comprehension\/\" target=\"_blank\"><\/a><a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-dictionary-comprehension\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-dictionary-comprehension\/\" target=\"_blank\">Dictionary Comprehension<\/a> converts the string to <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-lower\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-lower\/\" target=\"_blank\">lowercase<\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-re-findall\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-re-findall\/\" target=\"_blank\"><code>re.findall()<\/code><\/a> searches for and tallies each specified vowel. <\/p>\n<p>The results save to <code>vcount<\/code> and are output to the terminal.<\/p>\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\">\n<div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Python Regex re.search() - A Simple Guide with Example\" width=\"780\" height=\"439\" src=\"https:\/\/www.youtube.com\/embed\/Mv2VVpUgypc?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div>\n<\/figure>\n<p><strong>Output<\/strong><\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code>{'a': 8, 'e': 3, 'i': 0, 'o': 4, 'u': 3}<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<hr class=\"wp-block-separator\"\/>\n<h2>Method 2: Use List Comprehension and count()<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">This example uses <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/list-comprehension\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/list-comprehension\/\" target=\"_blank\">List Comprehension<\/a> to tally the number of specified vowels in a string. The results return in a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-lists\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\">List<\/a> format.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"2\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">saying = 'Saskatchewan! Where you can watch your dog run away for 3 days.'\nvcount = [saying.lower().count(x) for x in 'aeiou']\nprint(vcount)<\/pre>\n<p>This code declares the string <code>saying<\/code>. Then, <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/list-comprehension\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/list-comprehension\/\" target=\"_blank\">List Comprehension<\/a> converts the string to <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-lower\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-lower\/\" target=\"_blank\">lowercase<\/a> and searches for and tallies each specified vowel. <\/p>\n<p>The results save to variable <code>vcount<\/code> and are output to the terminal.<\/p>\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\">\n<div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Python String Count Method - A Short Tutorial\" width=\"780\" height=\"439\" src=\"https:\/\/www.youtube.com\/embed\/V3g4uE6j_E0?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div>\n<\/figure>\n<p>Output<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code>[8, 3, 0, 4, 3]<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p class=\"has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/13.1.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/><strong>Note:<\/strong> This output displays the totals but not their associated vowel.<\/p>\n<hr class=\"wp-block-separator\"\/>\n<h2>Method 3: Use Counter() and count.update()<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">This example calls the <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/collections.html\" data-type=\"URL\" data-id=\"https:\/\/docs.python.org\/3\/library\/collections.html\" target=\"_blank\">Collections<\/a> library and uses <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/collections.html\" data-type=\"URL\" data-id=\"https:\/\/docs.python.org\/3\/library\/collections.html\" target=\"_blank\"><code>Counter()<\/code><\/a> to count the number of specified vowels in a string. <\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"2,5-6\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">saying = 'Saskatchewan! Where you can watch your dog run away for 3 days.'\ncount = Counter() for i in saying: if i in 'aeiou': count.update(i.lower()) print(dict(count))<\/pre>\n<p>This code declares the string <code>saying <\/code>and initiates the <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/collections.html\" data-type=\"URL\" data-id=\"https:\/\/docs.python.org\/3\/library\/collections.html\" target=\"_blank\"><code>Counter()<\/code><\/a> object, <code>count<\/code>. <\/p>\n<p>A <code><a href=\"https:\/\/blog.finxter.com\/python-loops\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-loops\/\" target=\"_blank\" rel=\"noreferrer noopener\">for<\/a><\/code> loop instantiates and traverses through each character converting to <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-lower\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-lower\/\" target=\"_blank\">lowercase<\/a>, searching for and tallies each specified vowel. <\/p>\n<p>The results save to <code>count<\/code> and are output to the terminal.<\/p>\n<p>If this code was output to the terminal using <code>print(count)<\/code>, the output would be as follows:<\/p>\n<p><strong>Output <\/strong>using <code>print(count)<\/code><\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code>Counter({'a': 8, 'o': 4, 'e': 3, 'u': 3})<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>Placing <code>count<\/code> inside <code><a href=\"https:\/\/blog.finxter.com\/python-dict\/\" data-type=\"post\" data-id=\"19866\" target=\"_blank\" rel=\"noreferrer noopener\">dict()<\/a><\/code> removes the word <code>Counter<\/code> and surrounding braces <code>()<\/code>.<\/p>\n<p><strong>Output<\/strong> using <code>print(dict(count))<\/code><\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code>{'a': 8, 'e': 3, 'i': 0, 'o': 4, 'u': 3}<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p class=\"has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/13.1.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/><strong>Note:<\/strong> This method produces the same output as Method 1 but with four (4) additional lines of code.<\/p>\n<hr class=\"wp-block-separator\"\/>\n<h2>Method 4: Use For and count()<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">This example uses a <a href=\"https:\/\/blog.finxter.com\/python-loops\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-loops\/\"><code>for<\/code><\/a> loop and <a href=\"https:\/\/blog.finxter.com\/python-string-count\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-count\/\" target=\"_blank\" rel=\"noreferrer noopener\"><code>string.count()<\/code><\/a> to tally the number of specified vowels in a string. The results return as a string.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"4\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">saying = 'Saskatchewan! Where you can watch your dog run away for 3 days.'\ntmp = ''\nfor i in 'aeiou': tmp += i + ':' + str(saying.count(i)) + ' '\nprint(tmp)<\/pre>\n<p>This code declares the string <code>saying <\/code>and initiates a variable <code>tmp<\/code>. <\/p>\n<p>A <code><a href=\"https:\/\/blog.finxter.com\/python-loops\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-loops\/\" target=\"_blank\" rel=\"noreferrer noopener\">for<\/a><\/code> loop instantiates and traverses through each character, searching for and tallying each specified vowel. The results convert to a string, save to <code>tmp<\/code>, and are output to the terminal.<\/p>\n<p><strong>Output<\/strong><\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code> a:8 e:3 i:0 o:4 u:3<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<hr class=\"wp-block-separator\"\/>\n<h2>Method 5: Use map() and count()<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">This example uses <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-map\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-map\/\" target=\"_blank\"><code>map()<\/code><\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-list-count\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-list-count\/\" target=\"_blank\"><code>count()<\/code><\/a> to tally the number of specified vowels in a string. <\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"2\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">saying = 'Saskatchewan! Where you can watch your dog run away for 3 days.'\nprint(*map(saying.lower().count, 'aeiou'))<\/pre>\n<p>This code declares the string, <code>saying<\/code> converts the string to <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-lower\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-lower\/\" target=\"_blank\">lowercase<\/a>, and tallies the specified vowel. The results are output to the terminal.<\/p>\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\">\n<div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Mastering the Python Map Function [+Video]\" width=\"780\" height=\"439\" src=\"https:\/\/www.youtube.com\/embed\/tqph6mWC3m8?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div>\n<\/figure>\n<p><strong>Output<\/strong><\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code> 8 3 0 4 3<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<hr class=\"wp-block-separator\"\/>\n<h2>Summary<\/h2>\n<p>In this case, <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-lower\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-lower\/\" target=\"_blank\"><code>lower()<\/code><\/a> was not required as you could see no vowels were in uppercase. However, you may not always know what a string will contain. In this case, best to convert to either lowercase or uppercase.<\/p>\n<p>These five (5) methods of counting vowels in a string should give you enough information to select the best one for your coding requirements.<\/p>\n<p>Good Luck &amp; Happy Coding!<\/p>\n<hr class=\"wp-block-separator\"\/>\n","protected":false},"excerpt":{"rendered":"<p>Rate this post Problem Formulation and Solution Overview In this article, you&#8217;ll learn how to count the number of vowels in a string. To make it more fun, we have the following running scenario: In Canada, we have a province called Saskatchewan. This province has a large amount of flat land. In this article, we [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-124664","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/124664","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=124664"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/124664\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=124664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=124664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=124664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}