摘要:
1 __author__ = 'liunnis' 2 #-*-coding:utf-8 -*- 3 a=[1,2,3,4,4] 4 print a 5 print list(set(a)) 6 b=[str(i) for i in a] 7 print list(set(b)) 8 #the re... 阅读全文
摘要:
@原网站因为tuple不可变,所以代码更安全。如果可能,能用tuple代替list就尽量用tuple。tuple的陷阱:当你定义一个tuple时,在定义的时候,tuple的元素就必须被确定下来,比如:>>> t = (1, 2)>>> t(1, 2)如果要定义一个空的tuple,可以写成():>>>... 阅读全文
摘要:
在面向对象(OOP)的设计模式中,decorator被称为装饰模式。OOP的装饰模式需要通过继承和组合来实现,而Python除了能支持OOP的decorator外,直接从语法层次支持decorator。Python的decorator可以用函数实现,也可以用类实现。decorator可以增强函数的功... 阅读全文
摘要:
在面向对象(OOP)的设计模式中,decorator被称为装饰模式。OOP的装饰模式需要通过继承和组合来实现,而Python除了能支持OOP的decorator外,直接从语法层次支持decorator。Python的decorator可以用函数实现,也可以用类实现。decorator可以增强函数的功... 阅读全文