Welcome to the Python Features Quiz!
Features are a elementary a part of Python that assist make code reusable, readable, and modular. This quiz will take a look at your data of Python capabilities, together with syntax, arguments, return values, scope, built-in capabilities, and extra.
Desk of Contents:
- Python quizzes for rookies collection
Features Quiz
Quiz Questions
1. What’s the right method to outline a operate in Python?
a) operate my_func():
b) def my_func:
c) def my_func():
d) create operate my_func()
Reply
c) def my_func():
2. What key phrase is used to exit a operate and return a worth?
a) exit
b) cease
c) return
d) break
Reply
c) return
3. What would be the output of the next code?
def add(a, b):
return a + bprint(add(2, 3))
a) 2 + 3
b) 5
c) None
d) Error
Reply
b) 5
4. What would be the output of this code?
def my_func(x=5):
return x * 2print(my_func())
a) 10
b) 5
c) None
d) Error
Reply
a) 10
5. What’s the default return worth of a operate that doesn’t explicitly return a worth?
a) 0
b) None
c) False
d) Empty String
Reply
b) None
6. Which of the next is NOT a sound operate identify?
a) def _my_func():
b) def 2nd_function():
c) def myFunc():
d) def func_123():
Reply
b) def 2nd_function():
7. What’s the right method to name a operate named greet
?
a) name greet()
b) greet()
c) run greet()
d) execute greet()
Reply
b) greet()
8. What would be the output of this code?
def my_func(a, b=10):
return a + bprint(my_func(5))
a) 15
b) 10
c) 5
d) Error
Reply
a) 15
9. What does the *args
parameter enable in a operate?
a) Accepts a set variety of arguments
b) Accepts a number of positional arguments
c) Accepts a number of key phrase arguments
d) Permits a operate to return a number of values
Reply
b) Accepts a number of positional arguments
10. What would be the output of this code?
def multiply(a, b=2):
return a * bprint(multiply(3, 4))
a) 12
b) 6
c) 8
d) Error
Reply
a) 12
11. What does **kwargs
do in a operate?
a) Accepts a number of positional arguments
b) Accepts a number of key phrase arguments
c) Accepts a set variety of arguments
d) Throws an error if additional arguments are handed
Reply
b) Accepts a number of key phrase arguments
12. What would be the output of this operate name?
def instance(x, y=5):
return x + yprint(instance(3, y=7))
a) 10
b) 8
c) 15
d) Error
Reply
a) 10
13. What’s a lambda operate?
a) A operate with a number of return values
b) A operate with no arguments
c) A small nameless operate
d) A operate that modifies world variables
Reply
c) A small nameless operate
14. What’s the output of this lambda operate?
sq. = lambda x: x * x
print(sq.(4))
a) 8
b) 16
c) 4
d) Error
Reply
b) 16
15. What’s the right method to go an arbitrary variety of key phrase arguments?
a) def func(**kwargs):
b) def func(*kwargs):
c) def func(***kwargs):
d) def func($kwargs):
Reply
a) def func(**kwargs):
16. Which assertion about Python capabilities is TRUE?
a) Features should at all times return a worth
b) A operate can modify world variables with out the world
key phrase
c) Features can have a number of return statements
d) Features can not settle for a number of arguments
Reply
c) Features can have a number of return statements
17. What would be the output of the next code?
def outer():
x = 10
def inside():
return x + 5
return inside()print(outer())
a) 15
b) 10
c) 5
d) Error
Reply
a) 15
18. What’s recursion in Python?
a) A operate calling itself
b) A operate returning a number of values
c) A operate modifying world variables
d) A operate taking no parameters
Reply
a) A operate calling itself
19. What is going to occur if a recursive operate doesn’t have a base case?
a) It’ll run indefinitely and trigger an error
b) It’ll return None
c) It’ll cease after 10 iterations
d) It’ll throw a syntax error
Reply
a) It’ll run indefinitely and trigger an error
20. What does the world
key phrase do in Python?
a) Declares a variable as immutable
b) Permits a operate to entry a world variable
c) Restricts a operate from modifying a variable
d) Creates a neighborhood variable
Reply
b) Permits a operate to entry a world variable
How did you do? 🎯
- 18-20 right → 🏆 Glorious! You’re a Python capabilities professional!
- 14-17 right → 👍 Nice job! Maintain practising.
- 10-13 right → 🙂 Good, however there’s room for enchancment.
- Under 10 → 🤔 No worries! Evaluation the ideas and take a look at once more.