CodeStudy.net
Toggle Menu
Home
Online Java Compiler
Tutorials
Java Tutorial
Python Tutorial
SQL Database Design
Blog
All Posts
Functions and Modules in Python
Test how well you can structure and reuse Python code.
1. What keyword is used to define a function in Python?
def
function
func
define
2. Which parameter type allows a function to accept an arbitrary number of positional arguments?
*args
**kwargs
default
keyword
3. What value does a Python function return if it has no explicit return statement?
None
0
False
Error
4. What is the scope of a variable defined inside a function?
Local
Global
Enclosing
Built-in
5. Which standard library module provides the sqrt() function for square roots?
math
numpy
random
os
6. Which of the following are valid ways to import a module in Python? (Select all that apply)
import math
from math import sqrt
math.import sqrt
import math as m
7. Which of the following are valid parameter types in a Python function definition? (Select all that apply)
Positional
Keyword-only
Default
*args
**kwargs
8. How can a global variable be modified inside a Python function? (Select all that apply)
Using the 'global' keyword before assignment
Using the 'nonlocal' keyword
Assigning to the variable without any keyword
Declaring 'global var' inside the function
9. Which are characteristics of a lambda function in Python? (Select all that apply)
Can contain multiple expressions
Returns a function object
Can have multiple parameters
Requires an explicit 'return' statement
10. A Python function can contain multiple return statements.
True
False
11. The __name__ variable of a module is set to '__main__' when the module is imported into another script.
True
False
12. Default parameters in Python are evaluated once when the function is defined, not each time the function is called.
True
False
13. What keyword is used to define a function in Python? (lowercase, single word)
14. What is the standard file extension for a Python module? (include the dot)
15. What is the output of this code: def greet(name='Guest'): return f'Hello {name}'; greet() (enter the text exactly)
Reset
Answered 0 of 0 — 0 correct