Mutable" and "Immutable
Mutable: Something that can be changed after it is created.
Immutable: Something that cannot be changed after it is created.
Mutable Program
a = [1,2,3,4,]
[Link](5);
print(a)
Immutable Program
x=5
print(“before”,x)
x = x+1
print(“after”,x)
✅ What are Python Functions?
A function in Python is a block of code that runs only when you call it. It is used to
organize code, avoid repetition, and make the program clean and reusable.
Why Use Functions?
To reuse code
To break problems into smaller steps
To make code easier to understand
Program
# Function definition
def greet():
print("Hello! Welcome to Python.")
# Calling the function
greet()
Q3:Write a Python program that takes a list of numbers and
finds the factorial of each number using a recursive function.
What is Recursion?
A function that calls itself again and again is called recursion.
❗ What is Factorial?
The factorial of a number means:
n × (n-1) × (n-2) × ... × 1
Example: 4! = 4 × 3 × 2 × 1 = 24
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
numbers = [2, 3, 4]
for num in numbers:
print("Factorial of", num, "is", factorial(num))
Result Display
Factorial of 2 is 2
Factorial of 3 is 6
Factorial of 4 is 24