七十四、super类
1、定义:
class super(object) | super(type, obj) -> bound super object; requires isinstance(obj, type) | super(type) -> unbound super object | super(type, type2) -> bound super object; requires issubclass(type2, type) | Typical use to call a cooperative superclass method: | class C(B): | def meth(self, arg): | super(C, self).meth(arg)
2、解释:用于调用父类的方法,尤其适用于覆写父类该同名方法的时候
3、举例:
class FooParent(object): def __init__(self): self.parent = 'I\'m the parent.' print 'Parent' def bar(self,message): print message,'from Parent' class FooChild(FooParent): def __init__(self): super(FooChild,self).__init__() print 'Child' def bar(self,message): super(FooChild, self).bar(message) print 'Child bar fuction' print self.parent if __name__ == '__main__': fooChild = FooChild() fooChild.bar('HelloWorld') 结果: Parent Child HelloWorld from Parent Child bar fuction I'm the parent.
七十五、tuple类
1、定义:
class tuple(object) | tuple() -> empty tuple | tuple(iterable) -> tuple initialized from iterable's items | | If the argument is a tuple, the return value is the same object.
2、解释:初始化一个元组
3、举例:
>>> c set([1, 2]) >>> tuple(c) (1, 2) >>> tuple() () >>> tuple("1234") ('1', '2', '3', '4') >>> tuple(["a","b"]) ('a', 'b')
七十二、str类
1、定义:
class str(basestring) | str(object='') -> string | | Return a nice string representation of the object. | If the argument is a string, the return value is the same object. | | Method resolution order: | str | basestring | object
2、解释:返回一个对象的string表现方式
(以下省略)
七十、sorted方法
1、定义:
sorted(...) sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list
2、解释:生成一个整理好的list。其中iterable为可迭代对象,cmp为用来排序的比较函数, key为用来排序的关键值,reversed为是否倒序。
(以下省略)
Copyright © 2021.aoyanming个人博客站