Count the number of vowels in a given string. :param s: Input string to count vowels in. :return: Number of vowels in the input string. Examples: >>> count_vowels("hello world") 3 >>> count_vowels("HELLO WORLD") 3 >>> count_vowels("123 hello world") 3 >
(s: str)
| 1 | def count_vowels(s: str) -> int: |
| 2 | """ |
| 3 | Count the number of vowels in a given string. |
| 4 | |
| 5 | :param s: Input string to count vowels in. |
| 6 | :return: Number of vowels in the input string. |
| 7 | |
| 8 | Examples: |
| 9 | >>> count_vowels("hello world") |
| 10 | 3 |
| 11 | >>> count_vowels("HELLO WORLD") |
| 12 | 3 |
| 13 | >>> count_vowels("123 hello world") |
| 14 | 3 |
| 15 | >>> count_vowels("") |
| 16 | 0 |
| 17 | >>> count_vowels("a quick brown fox") |
| 18 | 5 |
| 19 | >>> count_vowels("the quick BROWN fox") |
| 20 | 5 |
| 21 | >>> count_vowels("PYTHON") |
| 22 | 1 |
| 23 | """ |
| 24 | if not isinstance(s, str): |
| 25 | raise TypeError("Input must be a string") |
| 26 | |
| 27 | vowels = "aeiouAEIOU" |
| 28 | return sum(1 for char in s if char in vowels) |
| 29 | |
| 30 | |
| 31 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected