码迷,mamicode.com
首页 > 编程语言 > 详细

Some tips about argument in python

时间:2016-06-27 17:44:45      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:different   dynamic   function   python   between   

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

标签:different   dynamic   function   python   between   

原文地址:http://luluuy.blog.51cto.com/279347/1793339

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!