这可能很奇怪,但我想声明一个没有固定值的变量,但以某种方式“链接”到函数的结果。目标是最终用户操作变量,但每次使用变量的值时,其值可能会发生变化。
这是我得到的当前结果:
from random import randint
def randomfun():
return randint(1, 100)
an_int = randomfun
print an_int # Print the function object
print an_int() # Print the result of randomfun()
我想得到的是print an_int实际调用randomfun(),但不必添加括号,并且类型an_int应该是randomfun返回类型。