1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| lst = [1]
lst.sort(key=str) lst.append('a')
lst.sort(key=str) lst.append(2) lst.sort(key=str) lst
print((lambda :0)())
print((lambda x,y=3:x+y)(5)) print((lambda x,y=3:x+y)(5,6)) 输出:11 print((lambda x,*,y=30:x+y)(5)) 输出:35 print((lambda x,*,y=30:x+y)(5,y=10)) 输出:15 print((lambda *args:(x for x in args))(*range(5))) 输出:<generator object <lambda>.<locals>.<genexpr> at 0x7f056cf7c138> print((lambda *args:[x+1 for x in args])(*range(5))) 输出:[1, 2, 3, 4, 5] print((lambda *args:{x+2 for x in args})(*range(5))) 输出:{2, 3, 4, 5, 6} [x for x in (lambda *args:map(lambda x:x+1,args))(*range(5))] 标准输出:Out:[1, 2, 3, 4, 5] [x for x in (lambda *args:map(lambda x:(x+1,args),args))(*range(5))] 标准输出: Out:[(1, (0, 1, 2, 3, 4)), (2, (0, 1, 2, 3, 4)), (3, (0, 1, 2, 3, 4)), (4, (0, 1, 2, 3, 4)), (5, (0, 1, 2, 3, 4))]
|