typeerror module sum() err 学习 col mos ans 情况
python的变量真的是很厉害的东西
我们知道计算机去找变量的值的时候是去找变量所指向的地址,然后把地址中的值取出来
而调用函数的时候,也是去找函数名所指向的地址,然后把地址中的函数提取出来
可以看到,都是去通过地址来调用的,而地址的格式是相同的,所以python就出现了一个函数的返回值是函数的这种情况
而函数名,我们也可以把它变成变量,真的是细思极恐。
感觉这样做的话,增加了代码的复杂性,并不是什么好的变成习惯
- print(abs(-10))
- abs=10
- print(abs(-10))
- 10
- Traceback (most recent call last):
- File "I:/深度学习/debug/debug.py", line 3, in <module>
- print(abs(-10))
- TypeError: ‘int‘ object is not callable
这里给一个函数是返回值的例子
- def lazy_sum(args):
- def sum():
- ans = 0;
- for k in args:
- ans = ans+k
- return ans
- return sum
- f = lazy_sum([1,2,3,4,5])
- print(f())
输出:
15
python变量,函数
typeerror module sum() err 学习 col mos ans 情况
原文:http://www.cnblogs.com/shensobaolibin/p/7896521.html
来源: http://www.bubuko.com/infodetail-2407040.html