zoukankan      html  css  js  c++  java
  • python:practice built-in function

    built-in function,is python already prepar for us ,anytime we can call built-in function when we needed it .

    all()  dict()   help()

    all([1,2,'')

    eval('1+2+3')

    filter(function,sequence)

    filter object  filter iterator

    map(function,sequence)

    map object map iterator

    map 

    can realize iterator function

    for example:

    str=['a','b','c','d']

    def fun(str):

       if  str !='a':

           return str

    ret =filter(fun,str)

    print(list(ret))

    str =['a','b','c','d']

    def fun2 (str):

       return str+'good'

    ret = map(fun2,str)

    print(ret)

    reduce:

    from fuctools import reduce

    def add(x+y):

      return x+y

    print(reduce(add,range(1,10))

    1+2+3+4+5+6+7+8+9=45

    the result of reduce is a value ,object not 

    lambda:

    add=lambda a,b:a+b

    conbine reduce and  lambda  realize factorial effect:

    from fuctools import reduce 

    reduce(lambda a,b:a+b,range(1,101))  5050

    reduce(lambda a,b:a*b,range(1,10))

  • 相关阅读:
    JAVA多线程之AQS
    LRU算法
    JAVA设计之SPI
    JAVA多线程之CAS
    操作系统之中断处理
    计算机领域思想
    操作系统之I/O
    操作系统之虚拟内存
    Mysql事务原理
    Mysql添加索引
  • 原文地址:https://www.cnblogs.com/alansuny/p/12496517.html
Copyright © 2011-2022 走看看