python基础05

1,冒泡排序法

1 li = [11,45,34,21,2,56,478,1,90]
2 for j in range(1,len(li)):
3     for i in range(len(li)-j):
4         if li[i] > li[i+1]:
5             temp = li[i]
6             li[i] = li[i+1]
7             li[i+1] = temp
8 print(li)

2,求斐波拉契数列排行某一个的数值

1 def f5(depth,a1,a2):
2     if depth == 6:
3         return a1
4     a3 = a2 + a1
5     r = f5(depth +1,a2,a3)
6     return r
7 
8 ret = f5(1,0,1)
9 print(ret)

 3,装饰器

 1 def outer(func):
 2     def inner():
 3         print('hello')
 4         print('hello')
 5         print('hello')
 6         r = func()
 7         print('end')
 8         print('end')
 9         print('end')
10         return r
11     return inner
12 
13 @outer
14 def f1():
15     print('F1')
16 #1,执行outer函数,并将其下面的的函数当作参数传递给outer。
17 #2,将outer的返回值重新赋值给f1。
18 f1()

 3,正则表达式

 1 re re.findall('alex','fghuhuhfalexfhdj') 

posted @ 2017-03-02 13:19  leonardchen  阅读(65)  评论(0)    收藏  举报