Python: 练习 不定长参数Python: 练习 不定长参数Python: 练习 不定长参数Python: 练习 不定长参数
  • 首页
  • 博客
  • 书签
  • 文件
  • 分析
  • 登录

Python: 练习 不定长参数

发表 admin at 2022年8月15日
类别
  • Practice
标签
a = 'aa'
b = 'bb'
tuple_ = (a, b)
dict_ = {'c': 'cc', 'd': 'dd'}


def test(*args, **kwargs):
    print(args)
    for item in args:
        print(item)
    print(kwargs)
    for key, value in kwargs.items():
        print(key, value)


if __name__ == '__main__':
    test('vv', 'ww', x='xx', y='yy', *tuple_, **dict_)


结果:

('vv', 'ww', 'aa', 'bb')
vv
ww
aa
bb
{'x': 'xx', 'y': 'yy', 'c': 'cc', 'd': 'dd'}
x xx
y yy
c cc
d dd

进程已结束,退出代码0

发表回复 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

类别

  • Cat
  • Python
  • MySQL
  • Django
  • Html/CSS
  • JavaScript
  • Vue
  • RegExp
  • php
  • Practice
  • Virtualization
  • Linux
  • Windows
  • Android
  • NAS
  • Software
  • Hardware
  • Network
  • Router
  • Office
  • WordPress
  • SEO
  • English
  • Games
  • Recipes
  • living
  • Memorandum
  • Essays
  • 未分类

归档

©2015-2023 艾丽卡 Blog support@alaica.com
      ajax-loader