• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
lummg-DAY
博客园    首页    新随笔    联系   管理    订阅  订阅

对def函数的参数认识

转载:https://www.cnblogs.com/Guido-admirers/p/6068702.html

如何理解函数的形式参数*args,**kwargs

形参*args的输出形式为tuple,当输入多个实参时,按实际顺序传入一一对应

形参**kwargs的输出形式为dict,当输入实际参数时,以字典的形式传入函数中

例如:

def i(kargs, *args, **kwargs):
print(kargs,type(kargs))
print(args,type(args))
print(kwargs,type(kwargs))
i("kdk","111","ppp","uuu",a=1,b=2,c=3)

输出结果:
kdk <class 'str'>
('111', 'ppp', 'uuu') <class 'tuple'>
{'a': 1, 'c': 3, 'b': 2} <class 'dict'>
posted @ 2019-04-09 11:33  lummg-DAY  阅读(209)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3