課程
/后端開發
/Python
/python進階
reduce()函數也是Python內置的一個高階函數。
2015-04-05
源自:python進階 2-5
正在回答
是的,注意底下加粗的部分
Help on built-in function reduce in module __builtin__:
reduce(...)
? ? reduce(function, sequence[, initial]) -> value
? ? Apply a function of two arguments cumulatively to the items of a sequence,
? ? from left to right, so as to reduce the sequence to a single value.
? ? For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
? ? ((((1+2)+3)+4)+5). ?If initial is present, it is placed before the items
? ? of the sequence in the calculation, and serves as a default when the
? ? sequence is empty.
舉報
學習函數式、模塊和面向對象編程,掌握Python高級程序設計
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2015-04-13
是的,注意底下加粗的部分
Help on built-in function reduce in module __builtin__:
reduce(...)
? ? reduce(function, sequence[, initial]) -> value
? ? Apply a function of two arguments cumulatively to the items of a sequence,
? ? from left to right, so as to reduce the sequence to a single value.
? ? For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
? ? ((((1+2)+3)+4)+5). ?If initial is present, it is placed before the items
? ? of the sequence in the calculation, and serves as a default when the
? ? sequence is empty.