我只是偶然發(fā)現(xiàn)如何檢查字符串是否以元音開頭?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 函數(shù),它應(yīng)該打印出以元音字母開頭的單詞
1 回答

楊__羊羊
TA貢獻1943條經(jīng)驗 獲得超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
提交
取消