Some tips about argument in python
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Some tips about argument in python相关的知识,希望对你有一定的参考价值。
def a(*args) # (dynamic) star symbol means this function could run with unlimited parameter.
args likes a tuple
e.g.
b = (1,2,3,4)
what‘s the different between a(b) and a(*b)
first one will put all b item as one item of *args.
second one will split b and put each one as a item of *args.
e.g. b="aaa" a(*b) # result is [a,a,a]
def a(**args) # double star will put argument like dict in memory.
e.g.
a(key1=‘value1‘,key2=‘value2‘...)
dic={‘k1‘:‘v1‘,‘k2‘,‘v2‘}
a(**dic)
almight argument
def f1(*args,**kwargs): #notice:Must place one-star before double-star, otherwise will get error
print(args)
print(kwargs)
以上是关于Some tips about argument in python的主要内容,如果未能解决你的问题,请参考以下文章