You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python编写元音检测函数return返回布尔值调用后无输出怎么办?

你的代码本身逻辑没有问题,没有输出是因为Python中函数的return语句仅会将运算结果返回给调用位置,不会自动把结果打印到控制台,你写的两种return写法都是符合语法规范的,不会影响执行结果。

你可以选择以下任意一种方式输出结果:

  • 直接打印函数调用结果
def search4vowels(word):
    vowels = set('aeiou')
    found = vowels.intersection(set(word))
    return bool(found)
        
print(search4vowels('test'))

运行上述代码后控制台会输出True。

  • 先接收返回值再打印
    如果你后续还需要用到这个判断结果,可以先用变量存储返回值,需要打印时再输出:
def search4vowels(word):
    vowels = set('aeiou')
    found = vowels.intersection(set(word))
    return bool(found)

# 接收返回值
has_vowel = search4vowels('test')
# 打印结果
print(has_vowel)

内容的提问来源于stack exchange,提问作者Kingster3742

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 07:12:03