2013年5月8日

摘要: 概要:一、创建类二、特性、函数和方法三、类的命名空间四、指定超类五、调查继承六、多个超类七、接口和内省一、创建类: 1 >>> __metaclass__ = type #确定使用新式类 2 >>> class Person: 3 4 def setName(self,name): 5 self.name = name 6 def getName(self,name): 7 return self.name 8 def greet(self): 9 print"Hello world ! I'm %s." % self... 阅读全文
posted @ 2013-05-08 20:14 飞奔的仙人掌 阅读(183) 评论(0) 推荐(0) 编辑
 
摘要: (一)创建函数:1、内建的callable函数可以用来判断函数是否可调用:(Python 2.7.4)1 >>> import math2 >>> x = 13 >>> y = math.sqrt4 >>> callable(x)5 False6 >>> callable(y)7 True【注意】函数callable在Python 3.0中不再可用,需要使用表达式hasattr(func._call_)代替。有关hasattr更多信息,参见第7章。2、使用def(或“函数定义”)语句创建函数:如:返回斐波 阅读全文
posted @ 2013-05-08 11:38 飞奔的仙人掌 阅读(175) 评论(0) 推荐(0) 编辑