后浪云Python教程:python关键字实参的使用
说明
1、在形参名前加两个星号**,表示创建一个名为形参的空字典,用来存储任意数量的键值对。
2、形参名**user_info中的两个星号允许Python创建一个名为user_info的空字典,并将收到的所有名称值对放入字典。
实例
#使用任意数量的关键字实参 def build_profile(first, last, **user_info): '''创建一个字典,其中包含我们知道的有关用户的一切。''' user_info['first_name'] = first user_info['last_name'] = last return user_info user_profile = build_profile('albert', 'einstein', location= 'princeton', field= 'physics') print(user_profile) # >>> {'location': 'princeton', 'field': 'physics', 'first_name': 'albert', 'last_name': 'einstein'}
以上就是python关键字实参的使用,希望对大家有所帮助。更多Python学习指路:后浪云python教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
版权声明:
作者:后浪云
链接:https://www.idc.net/help/176053/
文章版权归作者所有,未经允许请勿转载。
THE END