【问题标题】:Can there be nothing after "return"?“归来”之后就什么都没有了?
【发布时间】:2017-10-06 02:17:15
【问题描述】:
def analyze_html(url, root_url):
    savepath = download_file(url)
    if savepath is None:
        return  # here
    if savepath in proc_files:
        return  # here
    proc_files[savepath] = True
    print("analyze_html", url)
    html = open(savepath, "r", encoding="utf-8").read()
    links = enum_links(html, url)
    for link_url in links:
        if link_url.find(root_url) != 0:
            if not re.search(r".css$", link_url):
                continue 
        if re.search(r".(html|htm)$", link_url):
            analyze_html(link_url, root_url)
            continue
        download_file(link_url)

请参考我用双星号包裹的 if 语句。 我认为在“返回”之后总是必须有一些东西才能被返回。 这是什么意思?

【问题讨论】:

    标签: python python-3.x return


    【解决方案1】:

    return 本身与return None 相同

    请参阅language reference

    【讨论】:

    • 双倍。您也可以使用它提前终止函数
    猜你喜欢
    • 1970-01-01
    • 2017-03-19
    • 1970-01-01
    • 2011-03-29
    • 1970-01-01
    • 2013-06-12
    • 2011-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多