136 2108 0965
136 2108 0965
1039900924
1039900924@qq.com
The problem is to create a function that takes a string as input and returns a string with all vowels removed.
## Problem Analysis:
The task requires us to remove all vowels from a given string. Vowels in English are 'a', 'e', 'i', 'o', 'u' (both lowercase and uppercase). The function should be able to handle strings with mixed content including letters, numbers, punctuation, and whitespace.
## Solution Strategy:
The function will iterate through each character in the input string, check if it is not a vowel, and if true, append it to a new string which will be the result. This approach ensures that all characters except the vowels are copied to the output string.
## Implementation:
Here's the implementation of the function with detailed comments explaining each step:
def remove_vowels(s):
# Define a string containing all vowels (both lowercase and uppercase)
vowels = aeiouAEIOU
# Initialize an empty string to collect non-vowel characters
result =
# Iterate over each character in the input string
for char in s:
# Check if the character is not a vowel
if char not in vowels:
# If it's not a vowel, append it to the result string
result += char
# Return the string after removing all vowels
return result
## Example Usage:
print(remove_vowels(Hello, World!)) # Output: Hll, Wrld!
print(remove_vowels(Python3.8)) # Output: Pythn3.8
print(remove_vowels(AEIOUaeiou)) # Output:
This function efficiently removes all vowels from the input string while preserving other characters, as demonstrated in the example usage.