Discuss / Python / 例子里和我的返回结果不一样

例子里和我的返回结果不一样

Topic source

Pangzhi74890

#1 Created at ... [Delete] [Delete and Lock User]

廖老师的例子里的结果是

>>> f = lazy_sum(1, 3, 5, 7, 9)
>>> f
<function lazy_sum.<locals>.sum at 0x101c6ed90>

但是我的是

>>> f = lazy_sum(1, 3, 5, 7, 9)
>>> f
<function __main__.lazy_sum.<locals>.sum()>

最后我的f()就不能返回结果,返回的是

NameError: name 'args' is not defined

不知道为啥,是不是版本差异导致的呀。我的python是3.7的

Pangzhi74890

#2 Created at ... [Delete] [Delete and Lock User]

我傻了,是函数里面写错了


  • 1

Reply