def has_a_vowel(a_str):
for letter in a_str:
if letter in "aeiou":
return True # this leaves the function
print("Done!") # this prints only if no aeiou is in the string
return False # this leaves the function only after the full string was checked
或更简单:
def has_a_vowel(a_str):
return any(x in "aeiou" for x in a_str)
最好将
else: return False
和return False
从循环外移除:或更简单:
(但不会打印完成)。你知道吗
读数:
相关问题 更多 >
编程相关推荐