Python:打印函数结果将返回"None"(无). [英] Python: Printing the result of a function returns "None"

查看:102
本文介绍了Python:打印函数结果将返回"None"(无).的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些python代码,translate_string方法返回正确的值nevmban,但随后显示"None".

I have some python code, the translate_string method returns the correct value nevmban but then after it prints "None".

def secret_translate(letter):
    code = ord(letter)-ord('a')
    code = (code+13)%26
    newCode = chr(code+ord('a'))
    return newCode

def translate_string(string):

    newMsg = ''
    i = 0
    while i < (len(string)):

        print(secret_translate(string[i]),end='')
        i= i+1 

print(translate_string("arizona"))

程序打印:

nevmbanNone

我希望它打印nevmban无"来自哪里?

I expect it to print nevmban Where is the "None" coming from?

推荐答案

您正在打印translate_string函数的结果,该函数为None,因为没有显式的return语句.

You are printing the result of your translate_string function, which is None, as there is no explicit return statement.

这篇关于Python:打印函数结果将返回"None"(无).的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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