Heim >Backend-Entwicklung >Python-Tutorial >Python可变参数函数用法实例

Python可变参数函数用法实例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 11:13:061443Durchsuche

本文实例讲述了Python可变参数函数用法。分享给大家供大家参考。具体如下:

#!/usr/bin/python
def f1(a,b): print a,b
def f2(a,*b): print a,b
def f3(a,**b): print a,b
def f4(a,*b,**c): print a,b,c
def f5(a,b=2,c=3): print a,b,c
def f6(a,b=2,*c): print a,b,c
f1(1,2)
f1(b=2,a=1)
f2(1,2,3,4)
f3(1,x=2,y=3,z=4)
f4(1,x=2,y=3)
f5(1)
f5(1,4)
f6(1)
f6(1,3,4,5,4)

#!/usr/bin/python
def echoo(*args,**kwargs):
  print args,kwargs
echoo(1,2,a=3,b=4)
pargs = (1,2)
pkwargs = {'a':3,'b':4}
apply(echoo,pargs,pkwargs)

希望本文所述对大家的Python程序设计有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn