python中values、keys、items与*arg,**arg

来源:互联网 发布:freebsd vs ubuntu 编辑:程序博客网 时间:2024/06/16 16:53

python中values、keys、items:

>>> dict={1:"one","two":"er",3:"third"}>>> dict.values()['one', 'third', 'er']>>> dict.keys()[1, 3, 'two']>>> dict.items()[(1, 'one'), (3, 'third'), ('two', 'er')]>>> 

python中*args,**args: 

>>> def s1(*args):print args>>> s1("Zof")('Zof',)
>>> s1("Zof1","Zof2")('Zof1', 'Zof2')
//调用参数时,args就是元组

>>> def s2(**args):print args
>>> s2(p1=2,p2="er"){'p2': 'er', 'p1': 2}
//调用参数时,args就是字典,**将字典扩展为关键字参数,注意s2中是“=”号!



0 0