如何从 Python 的输出中删除 None? [英] How to remove None from the output in Python?

查看:579
本文介绍了如何从 Python 的输出中删除 None?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行我的 python 脚本时,我得到以下结果:

When in run my python script, i get the following result:

再试一次

import wikipedia
import time


def wiki_search(word):
    try:
        wikipedia.set_lang("es")
        wiki_result = wikipedia.summary(word, sentences=1, auto_suggest=True,   redirect=True)
        return wiki_result
    except wikipedia.exceptions.WikipediaException as e:
        return translate(e)
    
def translate(text):
   if "match" in str(text):
       print "Try again"
   else:
       print text

print wiki_search("Mark Zuckerb")
time.sleep(5)

为什么没有"出现以及如何从输出中删除它?

Why "None" appear and how to remove it from the output?

推荐答案

translate(text) 函数返回 None 因为它没有返回语句叫做.每个函数都以一个隐式的return None结束.

The function translate(text) returns None because it has no return statement that is reached when it is called. Every function ends with an implicit return None.

这篇关于如何从 Python 的输出中删除 None?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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