>> help(filter) Help on class filter in module builtins:..."/>
您好,登錄后才能下訂單哦!
?? filter()函數(shù)
?????????? filter()函數(shù)是個過濾器,它的作用就是在海量的數(shù)據(jù)里提取出有用的信息
>>> 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()函數(shù)有兩個參數(shù),第一個參數(shù)是一個函數(shù)也可以是None,第二個參數(shù)是可迭代對象iterable,如果第一個參數(shù)是
函數(shù),則將第二個參數(shù)可迭代對象的每個元素作為函數(shù)的參數(shù)進(jìn)行計(jì)算,把返回為True的值篩選出來;如果第一個參數(shù)是
None,則直接將第二個參數(shù)中為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]
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。