码迷,mamicode.com
首页 > 其他好文 > 详细

函数基础

时间:2018-08-27 14:13:08      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:osi   ==   rgs   *args   关键字   global   code   pytho   div   

 1 #!/usr/bin/env python
 2 #created by Baird
 3 
 4 position = "Shanghai"
 5 
 6 def func(x,y,z=1):
 7     return x+y+z
 8 
 9 def func2(*args):     #不固定参
10     print(args)
11 
12 func2(1,2,3,4)
13 
14 def func3(**kargs):    #把N个关键字参数转换成字典
15     print(kargs)
16 
17 def func4():
18     global position      #此方法可以修改全局变量
19     print(position)
20     position = "Beijing"
21 
22 func3(name=Baird,age=24)
23 
24 func4()
25 print(position)
26 
27 def func5(a):          #简单递归,python递归最大次数999
28     if a==1:
29         return(1)       #终止式,必须有
30     return(func5(a-1)+a)
31 print(func5(10))
32 
33 def func6(x,y,func):       #函数作形参
34     print(x+y+func(10))
35 func6(1,2,func5)        #函数作实参

 

函数基础

标签:osi   ==   rgs   *args   关键字   global   code   pytho   div   

原文地址:https://www.cnblogs.com/baird/p/9541357.html

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