Python练习

Posted 新起点1

tags:

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

def f1(a,b,c=0,*args,**kw):
    print(a=,a,b=,b,c=,c,args=,args,kw=,kw)
def f2 (a,b,c=0,*,d,**kw):
    print(a=,a,"b=",b,c=,c,d,kw=,kw)
    
f1("zs","hsdf",c=12)
a= zs b= hsdf c= 12 args= () kw= {}

f1("zs","hsdf",3,(1,2,3),kw=jac)
a= zs b= hsdf c= 3 args= ((1, 2, 3),) kw= {kw: jac}

f1("zs","hsdf",3,"dsf","dsf",kw=jac)
a= zs b= hsdf c= 3 args= (dsf, dsf) kw= {kw: jac}

f1("zs","hsdf",3,"dsf","dsf","dsffd",kw=jac)
a= zs b= hsdf c= 3 args= (dsf, dsf, dsffd) kw= {kw: jac}

f1("zs","hsdf",3,"dsf","dsf","dsffd",kw=jac,ke=df)
a= zs b= hsdf c= 3 args= (dsf, dsf, dsffd) kw= {kw: jac, ke: df}

f1("zs","hsdf",3,"dsf","dsf","dsffd",k=jac,ke=df,fc=kk)
a= zs b= hsdf c= 3 args= (dsf, dsf, dsffd) kw= {k: jac, fc: kk, ke: df}
f2("df","sdf",d=4,sdf="sdf",dsj=[1,2],jfj=3,sdjfh=(12,3))
a= df b= sdf c= 0 4 kw= {sdf: sdf, dsj: [1, 2], jfj: 3, sdjfh: (12, 3)}

 

args=(1,2,34)
kw={d:99,x:#}

f1(*args,**kw)
a= 1 b= 2 c= 3 args= (4,) kw= {d: 99, x: #}
这里可以理解*为可变参数,**kw为关键字参数,可变参数就是数量可变,所以可以用元组传入,关键字参数因为有名字和对应的数值两部分,正好就是dict,key-value对应

 

 


 



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

Python3练习题系列(03)

spring练习,在Eclipse搭建的Spring开发环境中,使用set注入方式,实现对象的依赖关系,通过ClassPathXmlApplicationContext实体类获取Bean对象(代码片段

csharp Epicor标准练习片段

golang 去练习片段

常用python日期日志获取内容循环的代码片段

python 有用的Python代码片段