首页 > 编程语言 > 详细

python-04

时间:2017-01-03 07:46:48      阅读:261      评论:0      收藏:0      [点我收藏+]

装饰器:

技术分享
 1 #装饰器
 2 
 3     
 4 def outer(fun):
 5     def wrapper():
 6         print 验证
 7         fun()
 8         print 1111111
 9     return wrapper
10     
11 @outer  
12 def Func1():
13     print func1
14 @outer   
15 def Func2():
16     print func2
17    
18 Func1()
19 Func2()
装饰器

 装饰器1:

技术分享
 1 def outer(fun):
 2     def wrapper(arg):
 3         print 验证
 4         fun(arg)
 5         print 1111111
 6     return wrapper
 7     
 8 @outer  
 9 def Func1(arg):
10     print func1,arg
11 
12 Func1(yang)
装饰器1

 类和对象:

类:

 1 class Person:
 2     xx = 12345
 3 
 4     def __init__(self,name):
 5         self.name = name
 6 
 7 p1= Person(李阳)
 8 print p1.name
 9 
10 p2= Person(老苟)
11 print p2.name

 类中的三种形式:   方法,特性,字段

技术分享
 1 class Province:
 2 
 3     memo = "23shengfen"   #静态字段,静态字段是属于类的
 4     def __init__(self,name,capital,leade):
 5     
 6         self.name = name   
 7         self.capital = capital   #动态字段,   类不能访问动态字段
 8         self.Leade = leade
 9 
10      #动态方法   
11     def Sport_meet(self):
12         print self.name + 开运动会
13 
14 
15     @staticmethod       #静态方法  静态方法属于类
16     def Foo():
17         print 每个省要带头反腐
18 
19     @property          #特性
20     def Bar(self):
21         #print self.name
22         return one
23 
24 hb = Province(河北,石家庄,)
25 sd = Province(山东,济南,)
26 #print Province.memo
27 #print hb.name
28 #print hb.memo      #对象可以访问静态字段,建议不要使用
29 
30 #hb.Sport_meet()
31 #sd.Sport_meet()
32 #Province.Foo() 
33 print hb.Bar                  #特性是这种访问形式,特性取返回值
View Code

 

python-04

原文:http://www.cnblogs.com/augustyang/p/6243625.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!