![]() |
| Simple visual explanation of Python Map, Filter, Lambda Functions, and Modules for beginners. |
In this lesson, we learn some important Python built-in functions and concepts in simple English.
🔹 1. Map()
map() is used to apply a function to every item in a list.
⚠ It does not return a list directly. You must convert it using list().
numbers = [1, 2, 3]
def square(x):
return x * x
result = map(square, numbers)
print(list(result))
🔹 2. Filter()
filter() selects items from a list based on a condition.
numbers = [1, 2, 3, 4, 5]
def is_even(n):
return n % 2 == 0
result = filter(is_even, numbers)
print(list(result))
🔹 3. Lambda Function
A lambda is a small one-line function without a name.
add = lambda x, y: x + y print(add(5, 3))
Using lambda with map:
numbers = [12, 9, 8] double_values = list(map(lambda x: x * 2, numbers)) print(double_values)
🔹 4. sum()
sum() adds all numbers in a list.
numbers = [1, 2, 3] print(sum(numbers))
🔹 5. isinstance()
isinstance() checks the data type of a variable.
x = 5.5 print(isinstance(x, float))
🔹 6. F-String
F-string is used to format strings easily.
name = "John"
age = 30
print(f"My name is {name} and I am {age} years old")
🔹 7. Modules
A module is a Python file that contains functions.
addition.py
def add(a, b):
return a + b
Using it in another file:
import addition print(addition.add(2, 3))
🔹 8. __name__ == "__main__"
This block runs only when we run the file directly.
if __name__ == "__main__":
print("Running directly")
🔹 9. Packages
A package is a folder that contains modules and an __init__.py file.
Packages help organize large projects properly.
🎯 These concepts are very important for Python beginners and real-world projects.
