python笔记-010-函数(下)

来源:互联网 发布:阿里巴巴农村淘宝兰西 编辑:程序博客网 时间:2024/06/06 20:52
# ★使用任意数量的关键字实参def build_profile(first, last, **user_info):    """创建一个字典,其中包含我们知道的有关用户的一切"""    profile = {}    profile['first_name'] = first    profile['last_name'] = last    for key, value in user_info.items():        profile[key] = value    return profileuser_profile = build_profile('albert', 'einstein',                            location='princeton',                            field='physics')print(user_profile)# ★形参**user_info中的两个星号让Python创建一个名为user_info的空字典# ★将函数存储在模块中:import语句

原创粉丝点击