可以使用循环遍历字符串的每个字符,判断是否为元音字母,如果是则复制到另一个字符串中。
以下是一个示例代码:
```python
def copy_vowels(string):
vowels = "aeiou"
new_string = ""
for char in string:
if char.lower() in vowels:
new_string += char
return new_string
# 测试
string1 = "Hello World"
string2 = copy_vowels(string1)
print(string2) # 输出 "eoo"
```
在上面的示例中,函数`copy_vowels`接受一个字符串参数`string`,然后遍历字符串的每个字符,使用`lower()`方法将字符转换为小写字母进行判断。如果字符为元音字母,则添加到`new_string`中。最后返回`new_string`。
制作不易,请点赞加关注