我只是偶然发现如何检查字符串是否以元音开头?def f(s): s = s.split(' ') for word in s: if word.startswith(any('aeiou')): print('starts with a vowel') print(s)r = 'd sljf l23j lekj 023 fls erj 50 isdl usdlw 'f(r)但是它给出了错误,出了什么问题?any() 是一个 bool 函数,它应该打印出以元音字母开头的单词
1 回答

杨__羊羊
TA贡献1943条经验 获得超7个赞
startswith接受字符串,你可以试试这个。
r = 'd sljf l23j lekj 023 fls erj 50 isdl usdlw '
for x in r.split():
if any(x.startswith(v) for v in 'aeiou'):
print(f'{x} starts with a vowel')
erj starts with a vowel
isdl starts with a vowel
usdlw starts with a vowel
添加回答
举报
0/150
提交
取消