【问题标题】:Program outputs error thing '<function score at 0x036374F8>' and doesn't output correct info when calling function and printing it程序输出错误'<function score at 0x036374F8>'并且在调用函数并打印时不输出正确的信息
【发布时间】:2017-12-03 21:23:20
【问题描述】:
我正试图让我的程序在通过预定义函数后打印出 score('9'),但它没有打印出正确的东西。
x=8
def score():
globz=x
print(globx)
globx+=1
return globx
x=(score)
print(x)
外壳显示:
这不是我想要的。为什么我看到的是这个而不是函数的输出?
【问题讨论】:
标签:
python
python-3.x
function
error-handling
【解决方案1】:
您没有调用您的 score 函数。您看到的值是对函数本身的引用。
使用score() 调用它并在您的x 变量中捕获它的返回值:
x = score()
print(x)