重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

filter()内置函数

   filter()函数

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:空间域名、网站空间、营销软件、网站建设、宜章网站维护、网站推广。

           filter()函数是个过滤器,它的作用就是在海量的数据里提取出有用的信息

>>> help(filter)
Help on class filter in module builtins:

class filter(object)
  |  filter(function or None, iterable) --> filter object
  | 
  |  Return an iterator yielding those items of iterable for which function(item)
  |  is true. If function is None, return the items that are true.
  | 
  |  Methods defined here:
  | 
  |  __getattribute__(self, name, /)
  |      Return getattr(self, name).
  | 
  |  __iter__(self, /)
|      Implement iter(self).
  | 
  |  __next__(self, /)
  |      Implement next(self).
  | 
  |  __reduce__(...)
  |      Return state information for pickling.
  | 
  |  ----------------------------------------------------------------------
  |  Static methods defined here:
  | 
  |  __new__(*args, **kwargs) from builtins.type
  |      Create and return a new object.  See help(type) for accurate signature.

       filter()函数有两个参数,第一个参数是一个函数也可以是None,第二个参数是可迭代对象iterable,如果第一个参数是

函数,则将第二个参数可迭代对象的每个元素作为函数的参数进行计算,把返回为True的值筛选出来;如果第一个参数是

None,则直接将第二个参数中为True的值筛选出来。

       例:

>>> list1=filter(None,[1,0,2,True,False])
>>> list(list1)
[1, 2, True]

>>> list(filter(lambda x:x%2,range(10)))
[1, 3, 5, 7, 9]


当前题目:filter()内置函数
文章分享:http://cqcxhl.cn/article/gdgggc.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP