python基础-函数的参数

101 阅读1分钟
# 动态传参
# * 表示接收所有动态的位置传参 *args
# ** 表示接收所有动态的关键字传参 **kwargs
# 参数顺序(重要):位置参数 > *args > 关键字参数 > **kwargs

# def chi(*food):
#     print(food)  # (1, 2, 3, 4) 结果为元组
#
#
# chi(1, 2, 3, 4)


# def chi(**food):
#     print(food)  # {'a': 11, 'b': 22, 'c': 33} 结果为字典
#
#
# chi(a=11, b=22, c=33)


# def test(*args):
#     print(args)  # (1, 2, 3, 4, 5)
#
#
# lst = [1, 2, 3, 4, 5]
# test(*lst)  # 在实参位置的*表示把列表打散成位置参数传递


# def test_dic(a, b, c):
#     print(a, b, c)  # 1 2 3
#
#
# lst_dic = {'a': 1, 'b': 2, 'c': 3}
# test_dic(**lst_dic)  # 在实参位置的**表示把字典打散成关键字参数传递

def test_res(a, b, c):
    return a, b, c


print(test_res(1, 2, 3))  # (1, 2, 3) ,返回多值为元组