study note10

Posted deakin-du

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了study note10相关的知识,希望对你有一定的参考价值。

参数组:

def test(*args):
    print(args)
test(1,2,3,4,5,6)
test(*[1,2,3])#转成元祖

def test1(a,*args):  #args只能接收位置参数,不能接受关键字参数
    print(a)
    print(args)
test1(1,2,3,4,5) #1会传给a,2345传给args

def test2(**kwargs):  #kwargs接收关键字参数,转成字典
    print(kwargs)
    print(kwargs[name])
    print(kwargs[age])
test2(name=deakin,age=28)#字典
test2(**{name:deakin,age:28})

def test3(name,**kwargs):
    print(name)
    print(kwargs)
test3(john,age=10,sex=M)

def test4(name,age=18,**kwargs):
    print(name)
    print(age)
    print(kwargs)
test4(deakin,job=IT)

def test5(name,age=28,*args,**kwargs):
    print(name)
    print(age)
    print(args)
    print(kwargs)
test5(amy,20,2,3,4,5,deakin,job=IT)  #2345,deakin都是位置参数,传给args转为元祖

打印结果:
test:
(1, 2, 3, 4, 5, 6)
(1, 2, 3)

test1:
1 (
2, 3, 4, 5) test2: {age: 28, name: deakin} deakin 28 {age: 28, name: deakin} deakin 28 test3: john {sex: M, age: 10} test4: deakin 18 {job: IT} test5: amy 20 (2, 3, 4, 5, deakin) {job: IT}

 

以上是关于study note10的主要内容,如果未能解决你的问题,请参考以下文章

Beginning Scala study note Basics of Scala

Study Notes: OpenMP gramma and notes

[Python Study Notes]with的使用

[20-04-26][Self-study Notes 12]Java Powerball

Cheetah Software Study Notes 2----the configuration pyqt

[Python Study Notes]批量将wold转换为pdf