2024-06-28 11:17:14 发布
网友
我刚刚偶然发现了如何检查字符串是否以元音开头
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函数,它应该打印以元音开头的单词
startswith接受字符串,您可以试试这个
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
startswith
接受字符串,您可以试试这个相关问题 更多 >
编程相关推荐