python函数中的返回值

2024-09-30 05:25:57 发布

您现在位置:Python中文网/ 问答频道 /正文

import urllib,re

def getver():
    url='https://github.com/Bendr0id/xmrigCC/releases'
    website = urllib.urlopen(url)
    html = website.read()
    links = re.findall(r'(?<=<a href=")[^"]*\bgcc-win64.zip\b', html)
    link=links[0]
    version=link.split('/')
    ver0=version[5]
    return ver0
getver()

我试图运行代码,但它没有输出任何东西,相反,当我用print替换return时,它会打印出正确的答案,即1.5.2。 我做错什么了?你知道吗


Tags: httpsimportregithuburlreturnversiondef
2条回答

你被交互式说话者的友好习惯愚弄了,这种习惯把你输入的任何简单表达的结果打印出来。你知道吗

运行程序时不会发生这种情况,因此需要确保使用print语句专门输出值。你知道吗

这在a rather obscure portion of the Python documentation处理语言语法时特别提到。你知道吗

将最后一行更改为:

print(getver())

相关问题 更多 >

    热门问题