美文网首页python
python模块之six

python模块之six

作者: wit92 | 来源:发表于2020-06-13 00:06 被阅读0次

代码案例

python3中使用python2的模块

Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> reduce
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'reduce' is not defined
>>> from six.moves import reduce
>>> def add(x, y):
...     return x+y
... 
>>> reduce(add,[1,2,3,4,5,6])
21
>>> reduce(lambda x ,y:x+y,[1,2,3,4,5])
15

相关文章

网友评论

    本文标题:python模块之six

    本文链接:https://www.haomeiwen.com/subject/ttytxktx.html