[Python]reduce function & lambda function & factorial
from functools import reduce i = int(input("input a number 1-10: ")) result = reduce(lambda a, b: a*b, [item for item in range(1,i+1)]) print(f‘factorial of {i+1} is {result}‘)
运行结果
input a number 1-10: 5 factorial of 6 is 120
相关推荐
meylovezn 2020-09-21
mmmjyjy 2020-07-16
typhoonpython 2020-06-11
Stranger 2020-05-16
PythonMaker 2020-04-22
QianYanDai 2020-04-18
千锋 2020-04-11
SDUTACM 2020-03-05
fly00love 2020-03-05
f = lambda x, y, z: x + y + z # returns a function that can optionally be assigned a name. def func:
sschencn 2020-02-21
wklken的笔记 2020-01-30
GhostLWB 2020-01-30
sulindong0 2020-01-19
chinademon 2020-01-12
mieleizhi0 2020-01-11
samsai00 2020-01-06