Python3 函数参数

 1 # # 常规参数
 2 # def jiafa(a,b):
 3 #     print(a+b)
 4 # 
 5 # jiafa(5,6)
 6 # 
 7 # 
 8 # def xinxi(name,location,sex='male'):    # 默认参数在其他参数的后面
 9 #     print('姓名:%s'%name)
10 #     print('性别:%s'%sex)
11 #     print('故乡:%s'%location)
12 # 
13 # 
14 # xinxi('bob','shanxi')
15 # 
16 # # 可变长参数
17 # def add(*jiafa):    # *之后跟一个元组,名字随意,一般写args(无命名参数)
18 #     print(jiafa)
19 #     sum = 0
20 #     for i in jiafa:
21 #         sum += i
22 #     print(sum)
23 # add(5,5,5)
24 # 
25 # def informations(**info):   # **之后跟一个字典,名字随意,一般写kwargs(有命名参数)
26 # 
27 #     for i in info:  # i是键,info是值
28 #         print('%s:%s'%(i,info[i]))
29 # informations(name = 'Lily',age = 18,sex = 'female',job = 'policewoman',location ='beijing')
30 # 
31 # def test(*a,**b):
32 #     print(a,b)
33 # test('asd',2,22,['asd',1],(1,2,3,4,5),name = 'bob')
34 
35 '''
36 关于不定长参数的位置 *agrs 放在左边, **kwargs 放在右边
37 默认值加不定长参数的左边
38 顺序:关键字参数,默认值参数,*args,**kwargs
39 '''

 

posted @ 2017-10-14 10:18  Infi_chu  阅读(360)  评论(0编辑  收藏  举报