分模块积累,此模块为【lambda 匿名函数】。
1. 简单用法:
'''定义单个参数的匿名函数''' f1=lambda x:pow(x,2) f1(5) '''定义多个参数的匿名函数''' f2=lambda x,y:x+y f2(5,6)
2. 复杂用法:
students=[ {'sno':101,'sname':'小张','sgrade':88}, {'sno':102,'sname':'小王','sgrade':99}, {'sno':103,'sname':'小李','sgrade':77}, {'sno':104,'sname':'小赵','sgrade':66}, ] sorted(students,key=lambda x:x['sgrade'])#x代表列表的每个元素,x['sgrade']为返回值
-END
标签:sname,函数,PYTHON,sno,sgrade,匿名,lambda From: https://www.cnblogs.com/peitongshi/p/16927748.htmlhttps://www.bilibili.com/video/BV1pW411P7pr/?spm_id_from=333.337.search-card.all.click&vd_source=efad7d657bca9605bbc1590a798ed819
https://www.bilibili.com/video/BV1SG411H7e1?p=11&vd_source=efad7d657bca9605bbc1590a798ed819