zoukankan      html  css  js  c++  java
  • Python 一些内置函数的总结~~~~

    1. type()

    两种用法

    a. 当传入参数为一个时,返回值为参数的类型

    b. 当传入参数为三个时,type(name, bases, dict)
    name: 类名
    bases: 继承父类的元组,可继承也可不继承
    dict: 构成类属性和方法的键值对(方法在外部定义,直接引用).
    返回一个类对象
    class TestBasic(object):
        @staticmethod
        def parent():
            print "this is parent method"
    
    
    def child(self):
        print "this is child method"
    
    
    test_property = {"name": "heihei", "child": child}
    
    Test = type("Test", (TestBasic,), test_property)
    
    test = Test()
    
    print test.name
    test.child()
    test.parent()
    

    运行结果:

    heihei
    this is child method
    this is parent method

    2. reduce() 

    函数将一个数据集合(链表,元组等)中的所有数据进行下列操作:用传给 reduce 中的函数 function(有两个参数)先对集合中的第 1、2 个元素进行操作,得到的结果再与第三个数据用 function 函数运算,最后得到一个结果。 

    reduce(function, iterable[, initializer])

    参数:

    • function -- 函数,有两个参数
    • iterable -- 可迭代对象
    • initializer -- 可选,初始参数
  • 相关阅读:
    js-事件委托
    compass的使用
    Ruby与sass 与compass安装
    JavaScript对象属性 constructor
    JQuery中常用的 属性选择器
    css3新增的背景属性
    js操作符
    Python04---重要函数
    Python03---内置模块
    Python02---整数,字符串,元组,列表,集合,字典
  • 原文地址:https://www.cnblogs.com/scircumsky/p/11648760.html
Copyright © 2011-2022 走看看