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实现HTML标签转义及反转义
    mvc中服务器端、客户端属性验证
    Ajax.ActionLink参数详解
    Ajax.BeginForm参数详解
    AjaxHelper简介
    将博客搬至CSDN
    Sequelize小记
    端口: 查看端口状态
    搭建git服务器
  • 原文地址:https://www.cnblogs.com/scircumsky/p/11648760.html
Copyright © 2011-2022 走看看