What is the purpose of the filter() function in Python?

Python >   Python List >   Python List  

Long Question

310


Answer:

The filter() function in Python is used to filter a sequence (list, tuple, etc.) by applying a test function to each element of the sequence. The test function should return a boolean value, indicating whether or not the element should be included in the filtered sequence. The filtered sequence is returned as a new sequence (a filter object) containing only the elements for which the test function returned True.

Syntax: filter(function, iterable)

where,

  • function is the test function to be applied to each element of the iterable
  • iterable is the sequence to be filtered (list, tuple, etc.)


This Particular section is dedicated to Question & Answer only. If you want learn more about Python. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.