Decorators ,Lambda Functions and Sequences of Python
来源:互联网 发布:轩辕剑坐骑10进阶数据 编辑:程序博客网 时间:2024/05/16 17:46
#using Decorators not understand reallyimport operatorclass Files: def __init__(self,**kwargs): self.properties =kwargs def copy(self): print "copying" def move(self): print "moving " def remove(self): print "deleting" def get_properites(self): return self.properties def get_property(self,key): return self.properties.get(key) @property def privacy(self): return self.properties.get("privacy") @privacy.setter def privacy(self,c): self.properties['privacy'] =c @privacy.deleter def privacy(self): del self.properties['privacy'] #Lambda functions def calcuate(self,x): return x*2 def cal2(self,j): t = lambda x: x * 2 return t(j) # Multiple Arguments Using lambda def MulArg(self,x,y): t= lambda x,y:(x*y,x+y) return t(x,y) #Operators and KeyWords for sequences def OKs(self): t = tuple(range(29)) # tuple can not changed l= list(range(23)) # list can change print t print l # itemgetter Not easy really def itemgetee(self): getseconditem = operator.itemgetter(1) ls =['a','b','c','d','e'] tu=('a','gg','d','c','f') print (getseconditem(ls)) print (getseconditem(tu)) print (operator.itemgetter(1,3,5)('abcdefg'))def main(): # here not main(self) ,will get error TypeError: main() takes exactly 1 argument (0 given) imageDoc = Files(privacy="secret",you="your") print imageDoc.get_property("privacy") print imageDoc.get_property("you") D = Files() D.privacy="dddddddddd" print D.privacy # will get dddddddd print imageDoc.calcuate(3) # works print D.calcuate(3) # works print D.cal2(3) print D.MulArg(13,7) print D.MulArg(13, 7)[0] print D.MulArg(13, 7)[1] print D.OKs() D.itemgetee()main()
0 0
- Decorators ,Lambda Functions and Sequences of Python
- Decorators and Functional Python
- Decorators and Functional Python
- Decorators and Functional Python
- python decorators, classmethod and staticmethod
- python lambda 表达式(Python: Lambda Functions)
- Python[六]:Tuples and Sequences
- python decorators
- Python Decorators
- [Python]Decorators
- python -decorators
- A Byte of Python -- Functions
- Derivatives of scalars, vector functions and matrices
- Functions of Protocols and Transmission Speed
- Decorators I: Introduction to Python Decorators
- The default parameter of python functions
- python 的函数Decorators
- python标注,@decorators
- Linux常用命令
- Oracle(6)Oracle数据库启动流程
- Intent和PendingIntent的区别
- WPF 柱状图报表饼图报表区域折线图报表横向柱状图报表折线图报表
- 迷宫最短路径问题(BFS)
- Decorators ,Lambda Functions and Sequences of Python
- 欢迎使用CSDN-markdown编辑器
- Linux命令find的35个实例
- adb shell ps
- VS不能调试的问题
- 编译GDAL步骤(64位)
- Android BroadcastReceiver的注册方式静态和动态
- 利用URL Protocol实现网页调用本地应用程序
- [pytorch] 利用batch normalization对Variable进行normalize/instance normalize