2020年1月10日 MRKJ 参数 page169

result=lambda x,y,z,……:x+y+z

import math
def circle(r):
    return math.pi*r*r
r=10
print(circle(r))

result=lambda x:math.pi*x*x
print(result(10))

>>>>>

314.1592653589793
314.1592653589793

sort函数   list.sort(cmp=None, key=None, reverse=False)
sort中key对应的是函数名,来表达排序规则(内部将list中的值遍历来使用新的函数排序) 也可以用lambda
msg=[(12,22),(22,23),(12,31),(24,25)]
msg.sort(key=lambda x:(x[0],x[1]))
print(msg)


def takesecond(e):
    return e[1]
msg.sort(key=takesecond,reverse=True) #
print(msg)

》》》》

[(12, 22), (12, 31), (22, 23), (24, 25)]
[(12, 31), (24, 25), (22, 23), (12, 22)]

猜你喜欢

转载自www.cnblogs.com/python1988/p/12177958.html