Functions
Learning how to define and call functions, understanding parameters, return values, and scope. Here are 25 questions related to defining and calling functions, understanding parameters, return values,
1
What is a function in Python?
def greet():
print("Hello, World!")
greet()2
How do you define a function with parameters?
def add(a, b):
return a + b
result = add(3, 5)
print(result)3
What is a default parameter in a function?
def greet(name="Guest"):
print(f"Hello, {name}!")
greet()
greet("Alice")4
How do you define a function with multiple return values?
5
What are keyword arguments?
6
How do you define a function with variable-length arguments?
7
**What are kwargs in a function definition?
8
How does variable scope work in Python functions?
9
What is a lambda function?
10
How do you use a function as an argument to another function?
11
How can you call a function inside another function?
12
What is the difference between return and print in functions?
13
How do you handle exceptions inside a function?
14
What are function annotations?
15
How do you use a function inside a list comprehension?
16
How can you define a function with a nonlocal variable?
17
What is a closure in Python?
18
How do you use a function as a callback?
19
How can you pass a function as an argument with *args or **kwargs?
20
How do you create a recursive function?
21
What is a higher-order function?
22
How do you ensure a function’s execution time?
23
What is a function decorator?
24
How do you use function overloading in Python?
25
How do you use a function’s docstring?
Last updated