filter() — Easy Examples
Returns elements from an iterable for which a function returns True
Basic filter() usage
Simple demonstration of the filter() built-in function.
python
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] evens = list(filter(lambda x: x % 2 == 0, nums)) print(evens)
filter() is a built-in function that returns elements from an iterable for which a function returns true.
filter() with different inputs
Calling filter() with various argument types.
python
# More filter() examples print("filter() is a Python built-in function") print(f"Type: {type(filter)}")
filter() accepts different types of arguments and produces corresponding results.
Want to try these examples interactively?
Open Easy Playground