Check presence of vowels in a string

前端 未结 6 1096
温柔的废话
温柔的废话 2020-12-02 01:54

I need to check whether a vowel is present in a word. If it is, an operation should be carried out on the word say op(word). I want to avoid a for loop because

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 02:20

    You could use regex.

    import re
    
    if re.search('[AEIOU]', word, flags=re.I):
        # contains vowels
    else:
        # does not
    

提交回复
热议问题