Theory Questions
What is a function in Python?
What is a parameter in a function?
What is an argument in a function?
Explain the purpose of a return statement in a function.
Describe the global
keyword in Python functions.
What is function overloading? Does Python support it?
Describe the purpose of the *args
and **kwargs
parameters in function definitions.
Explain the difference between a built-in function and a user-defined function.
What is function scope in Python? How does it affect variable visibility?
What is the purpose of the pass
statement in a function?
Python Functions PPT
Programming Questions
Write a function to calculate the factorial of a given positive integer.
Create a function that takes a list of numbers and returns their sum.
Write a function that checks whether a given number is prime or not.
Implement a function to reverse a string.
Create a function that finds the maximum element in a list of numbers.
Write a function to calculate the Fibonacci sequence up to a given number of terms.
Implement a function to find the common elements between two lists.
Create a function that takes a string and returns the number of vowels it contains.
Create a function that takes a list of words and returns the longest word.
Write a function that removes duplicates from a list while preserving the order
Output Questions
def add(a, b):
return a + b
result = add(3, 5)
print(result)
def greet(name):
return “Hello, ” + name
message = greet(“Alice”)
print(message)
def square(x):
return x ** 2
num = 4
result = square(num)
print(result)
def calculate(a, b):
return a * 2, b * 3
x, y = calculate(2, 3)
print(x, y)
def is_even(n):
return n % 2 == 0
print(is_even(4))
print(is_even(7))
def greet(name, message=”Hello”):
return message + “, ” + name
print(greet(“Bob”))
print(greet(“Alice”, “Hi”))
def power(base, exponent=2):
return base ** exponent
print(power(3))
print(power(2, 4))
def print_info(name, age):
print(“Name:”, name)
print(“Age:”, age)
data = (“Alice”, 30)
print_info(*data)
def repeat_string(s, times=2):
return s * times
result = repeat_string(“abc”, 3)
print(result)
def concatenate_strings(*args):
return ” “.join(args)
result = concatenate_strings(“Hello”, “world”, “!”)
print(result)