A function is a block of code that performs a specific task and can be reused multiple times. Functions help us write clean, organized, and maintainable programs.
Key Points to Remember
- Functions are defined using the def keyword
- A function must be called to execute
- Parameters receive data, arguments send data
- return sends a value back to the caller
- print is only for displaying output
Basic Syntax
def add(a, b):
return a + b
1. What is a function in Python?
A function is a reusable block of code that performs a specific task.
2. Fill in the blank to define a function:
__ greet():
The
def keyword is used to define a function.
3. Which keyword is used to return a value from a function?
return sends a value back to the function caller.
4. What happens if a function has no return statement?
If no return is written, Python returns None by default.
5. Fill in the blank to call a function named add:
____(10, 20)
Functions are called using their name followed by parentheses.
6. Which of the following is a built-in function?
len() is a built-in Python function.
7. What are values passed to a function called?
Arguments are the actual values passed to a function.
8. Fill in the blank for default argument: (Hint: User)
def greet(name="____"):
Default arguments provide a value if no argument is passed.
9. Which variable is accessible only inside a function?
Local variables exist only inside the function.
10. Which is the correct function definition?
Functions are defined using the
def keyword.
11. Fill in the blank to return a value:
____ x * x
return sends result back to caller.
12. A function inside another function is used for?
Functions calling other functions improve modularity.
13. Which is better for logic – print or return?
return allows reuse of values in programs.
14. Fill in the blank to define function with parameter:
def square(____):
Parameters receive data inside functions.
15. Functions help in:
Functions reduce repetition and improve maintainability.
Your Score: 0 / 15
0 Comments