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 -- 可选,初始参数
  • 相关阅读:
    简明Secure boot介绍
    密码学有什么用?
    mkimage, no such file or dir
    嵌入式系统安全简介
    希尔排序
    jQuery选择器
    css 选择器
    安装 SQL Server 2008 和管理工具 SQL Server 2008 management studio 及相关问题解决
    mac下安装安卓开发环境
    IOS开发小记-内存管理
  • 原文地址:https://www.cnblogs.com/scircumsky/p/11648760.html
Copyright © 2011-2022 走看看