为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 python 中的所有元音上使用'开头'?

如何在 python 中的所有元音上使用'开头'?

慕容3067478 2023-06-06 10:38:31
我只是偶然发现如何检查字符串是否以元音开头?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


查看完整回答
反对 回复 2023-06-06
  • 1 回答
  • 0 关注
  • 123 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号