Skip to content

Latest commit

 

History

History
30 lines (17 loc) · 492 Bytes

3.2.1 元组和字典的拆包.md

File metadata and controls

30 lines (17 loc) · 492 Bytes

3.2.1 元组和字典的拆包

def demo(*args, **kwargs):

    print(args)

    print(kwargs)


# 元组变量/字典变量

gl_nums = (1, 2, 3)

gl_dict = {"name": "小明",
           "age": 21}

# 拆包格式:如果是元组,那么在元组变量前面添加一个 *
#         如果是字典,那么在字典变量前面添加两个 **
# 提示:多值参数函数定义相反

demo(*gl_nums, **gl_dict)

# 输出:
# (1, 2, 3)
# {'name': '小明', 'age': 21}