operator-example.py

# -*- coding: utf-8 -*-

# @Date    : 2018-11-01
# @Author  : Peng Shiyu

# operator 提供标准操作符接口,替换lambda

import operator
from functools import reduce

lst = [1, 2, 3, 4, -5]

# 计算
print(reduce(operator.add, lst))
# 5

print(list(map(operator.abs, lst)))
# [1, 2, 3, 4, 5]