Python 带星号( * 或 ** )的函数参数

博客涉及Java和C#两种编程语言中的数据结构相关内容,虽未给出具体内容,但可知围绕这两门语言的数据结构展开,数据结构在信息技术领域是重要基础,能助力程序高效运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

def singalAndDoubleStar(common, *args, **kwargs):
    print("Common args: ", common)
    print("Single args: ", args)
    print("Double args: ", kwargs)

singalAndDoubleStar("hello")
# Common args:  hello
# Single args:  ()
# Double args:  {}
singalAndDoubleStar("hello", "world", 000)
# Common args:  hello
# Single args:  ('world', 0)
# Double args:  {}
singalAndDoubleStar("hello", "world", 000, {"name": "Test", "age": 24})
# Common args:  hello
# Single args:  ('world', 0, {'name': 'Test', 'age': 24})
# Double args:  {}
singalAndDoubleStar("hello", "world", 000, **{"name": "Test", "age": 24})
# Common args:  hello
# Single args:  ('world', 0)
# Double args:  {'name': 'Test', 'age': 24}
singalAndDoubleStar("hello", ("world", 000), {"name": "Test", "age": 24})
# Common args:  hello
# Single args:  (('world', 0), {'name': 'Test', 'age': 24})
# Double args:  {}
singalAndDoubleStar("hello", *("world", 000), {"name": "Test", "age": 24}) 
# Common args:  hello
# Single args:  ('world', 0, {'name': 'Test', 'age': 24})
# Double args:  {}
singalAndDoubleStar("hello", *("world", 000), **{"name": "Test", "age": 24})
# Common args:  hello
# Single args:  ('world', 0)
# Double args:  {'name': 'Test', 'age': 24}
singalAndDoubleStar("hello", "world", 000, name='Test', age=24)
# Common args:  hello
# Single args:  ('world', 0)
# Double args:  {'name': 'Test', 'age': 24}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值