函数(二)

1、函数返回多个值:
1、函数如果返回多个值的话,它会把这几个值放到一个元组里面
2、函数如果返回多个值的话,也可以用多个变量来接收
def say():
    num1 = 1
    num2 = 2
    num3 = 3
    return num1,num2,num3
print(say())#(1, 2, 3)
res1,res2,res3 = say()
print(res1,res2,res3)#1  2  3

匿函数:lambda

lambda x: x+1 #冒号后面的是函数体,也是函数的处理逻辑,冒号前面的返回值

d = {'a':8,'b':2,'c':3}
#字典是无序,直接对字典排序是不存在的。
print(d.items())#dict_items([('a', 8), ('b', 2), ('c', 3)])
res = sorted(d.items(),key=lambda x:x[1])
#sort,循环调用
print(res)#[('b', 2), ('c', 3), ('a', 8)]



原文地址:https://www.cnblogs.com/hwtfamily/p/8969075.html