Return 语句在 sublime 文本编辑器中不起作用 [英] Return statement not working in sublime text editor

查看:35
本文介绍了Return 语句在 sublime 文本编辑器中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

def count_match(data,target): 
    count = 0 
    for i in data: 
        if i == target: 
            count += 1 
    return count 

count_match([1,2,3,5,6,5,6,6,6,4],6)


[Finished in 0.6s]

预期输出:4

为什么 return 语句在 sublime 文本编辑器中不起作用?

Why does the return statement not work in sublime text editor?

推荐答案

因为它是作为脚本执行的,并且脚本不会隐式打印任何内容.只需打印返回值:

Because it's being executed as a script, and scripts don't print anything implicitly. Simply print the return value:

result = count_match([1,2,3,5,6,5,6,6,6,4],6)
print(result)

这篇关于Return 语句在 sublime 文本编辑器中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆