5 marks
[Link] to pass a parameter to a function
Functions in Python are created and denoted with the def keyword followed by a function
name. The parameters of the function are stored in the parentheses.
For example: greet_customer(name) is a function that has (name) as its parameter.
Positional Arguments
Values are assigned to parameters in the order they are passed.
Eg
def greet(name, age):
print(“Hello”, name, “You are”,age,” years old.")
greet("Alice", 25)
Keyword Arguments
You specify which value goes to which parameter using parameter names.
Eg
def greet(name, age):
print(“Hello”, name, “You are”,age,” years old.")
greet(name="Bob", age=30)
Default Arguments
Parameters can have default values, used if no argument is passed.
Eg
def greet(name, age=18):
print(“Hello”, name, “You are”,age,” years old.")
greet("Charlie")
Variable-Length Arguments
1.*args for multiple positional arguments (tuple)
2.**kwargs for multiple keyword arguments (dictionary)
def fun(*args, **kwargs):
print(args)
print(kwargs)
fun(1, 2, name="Alice", age=25)
[Link] Program
def is_palindrome(s):
return s == s[::-1]
word = input("Enter a word: ")
if is_palindrome(word):
print("It's a palindrome!")
else:
print("Not a palindrome.")
✅ Example:
Enter a word: madam
It's a palindrome!
2 marks
3. Show the example for Boolean flag
found = False
numbers = [10, 20, 30, 40, 50]
target = 30
for num in numbers:
if num == target:
found = True
break
if found:
print("Number found!")
else:
print("Number not found.")
[Link] of calling non value
Non-value returning functions are used to perform actions like displaying output or modifying data
without returning a result, helping to organize and simplify code.
5. python modules
1. Built-in Modules
Already available in Python.
Example: math, random, datetime
2. User-defined Modules
Created by users to organize their own functions and classes.
6. Python modular Design
Modular design improves code reusability, readability, debugging, and allows easier maintenance
and teamwork.