python3中lambda函数

def make_repeater(n):
    return lambda s:s*n
twice=make_repeater(2)
 
print(twice('wwss'))
 
print(twice(2)) 
 
 
结果:

/Users/didi/Documents/pycarm/venv/bin/python /Users/didi/Documents/pycharm_workstation/lambda_test.py
wwsswwss
4

Process finished with exit code 0

猜你喜欢

转载自www.cnblogs.com/houyan-jessica/p/9260283.html